/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// It is possible that we're running so early that we might need to start // the thread manager ourselves. We do this here to guarantee that we have // the ability to start the persistent MTA thread at any moment beyond this // point.
nsresult rv = nsThreadManager::get().Init(); // We intentionally don't check rv unless we need it when // CoIncremementMTAUsage is unavailable.
// Calling this function initializes the MTA without needing to explicitly // create a thread and call CoInitializeEx to do it. // We don't retain the cookie because once we've incremented the MTA, we // leave it that way for the lifetime of the process.
CO_MTA_USAGE_COOKIE mtaCookie = nullptr;
HRESULT hr = wrapped::CoIncrementMTAUsage(&mtaCookie); if (SUCCEEDED(hr)) { if (NS_SUCCEEDED(rv)) { // Start the persistent MTA thread (mostly) asynchronously.
Unused << GetPersistentMTAThread();
}
return;
}
// In the fallback case, we simply initialize our persistent MTA thread.
// Make sure thread manager init succeeded before trying to initialize the // persistent MTA thread.
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); if (NS_FAILED(rv)) { return;
}
// Before proceeding any further, pump a runnable through the persistent MTA // thread to ensure that it is up and running and has finished initializing // the multi-threaded apartment.
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction( "EnsureMTA::EnsureMTA()",
[]() { MOZ_RELEASE_ASSERT(IsCurrentThreadExplicitMTA()); }));
SyncDispatchToPersistentThread(runnable);
}
// Note that, due to APC dispatch, we might reenter this function while we // wait on this event. We therefore need a unique event object for each // entry into this function. If perf becomes an issue then we will want to // maintain an array of events where the Nth event is unique to the Nth // reentry.
nsAutoHandle event(::CreateEventW(nullptr, FALSE, FALSE, nullptr)); if (!event) { return;
}
/** * While this function currently appears to be redundant, it may become more * sophisticated in the future. For example, we could optionally dispatch to an * MTA context if we wanted to utilize the MTA thread pool.
*/ /* static */ void EnsureMTA::SyncDispatch(nsCOMPtr<nsIRunnable>&& aRunnable, Option aOpt) {
SyncDispatchToPersistentThread(aRunnable);
}
} // namespace mscom
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.