Bug 1584568 - add a way to get the background event target; r=KrisWright

This function is needed for people whose needs don't map cleanly to
`NS_DispatchToBackgroundThread`, usually because they're using the event
target to do thread consistency checks.  Once we have this function, we
can start converting singleton threads/thread pools that want to use
functionality like the above.

Differential Revision: https://phabricator.services.mozilla.com/D47454

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nathan Froyd 2019-09-27 17:16:40 +00:00
Родитель b52f6bd330
Коммит e284917829
4 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -462,6 +462,16 @@ nsresult nsThreadManager::DispatchToBackgroundThread(nsIRunnable* aEvent,
return backgroundTarget->Dispatch(aEvent, aDispatchFlags);
}
nsresult nsThreadManager::GetBackgroundEventTarget(nsIEventTarget** aEventTarget) {
if (!mInitialized) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEventTarget> et(mBackgroundEventTarget);
et.forget(aEventTarget);
return NS_OK;
}
nsThread* nsThreadManager::GetCurrentThread() {
// read thread local storage
void* data = PR_GetThreadPrivate(mCurThreadIndex);

Просмотреть файл

@ -56,6 +56,8 @@ class nsThreadManager : public nsIThreadManager {
nsresult DispatchToBackgroundThread(nsIRunnable* aEvent,
uint32_t aDispatchFlags);
nsresult GetBackgroundEventTarget(nsIEventTarget** aEventTarget);
// Returns the maximal number of threads that have been in existence
// simultaneously during the execution of the thread manager.
uint32_t GetHighestNumberOfThreads();

Просмотреть файл

@ -529,6 +529,10 @@ nsresult NS_DispatchToBackgroundThread(nsIRunnable* aEvent,
return nsThreadManager::get().DispatchToBackgroundThread(aEvent, aDispatchFlags);
}
nsresult NS_GetBackgroundEventTarget(nsIEventTarget** aEventTarget) {
return nsThreadManager::get().GetBackgroundEventTarget(aEventTarget);
}
// nsAutoLowPriorityIO
nsAutoLowPriorityIO::nsAutoLowPriorityIO() {
#if defined(XP_WIN)

Просмотреть файл

@ -1706,6 +1706,11 @@ extern nsresult NS_DispatchToBackgroundThread(already_AddRefed<nsIRunnable> aEve
extern nsresult NS_DispatchToBackgroundThread(nsIRunnable* aEvent,
uint32_t aDispatchFlags = NS_DISPATCH_NORMAL);
/**
* Get the event target that NS_DispatchToBackgroundThread uses.
*/
extern nsresult NS_GetBackgroundEventTarget(nsIEventTarget** aEventTarget);
namespace mozilla {
/**