Bug 1355161 - provide a scriptable equivalent of NS_DispatchToMainThread, r=froydnj.

This commit is contained in:
Florian Queze 2017-04-14 18:27:32 +02:00
Родитель 2fcb7c6663
Коммит 65ba8f32ee
2 изменённых файлов: 25 добавлений и 0 удалений

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

@ -8,6 +8,7 @@
[ptr] native PRThread(PRThread);
interface nsIRunnable;
interface nsIThread;
/**
@ -79,4 +80,14 @@ interface nsIThreadManager : nsISupports
* application process.
*/
readonly attribute boolean isMainThread;
/**
* This queues a runnable to the main thread. It's a shortcut for JS callers
* to be used instead of
* .mainThread.dispatch(runnable, Ci.nsIEventTarget.DISPATCH_NORMAL);
* or
* .currentThread.dispatch(runnable, Ci.nsIEventTarget.DISPATCH_NORMAL);
* C++ callers should instead use NS_DispatchToMainThread.
*/
void dispatchToMainThread(in nsIRunnable event);
};

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

@ -348,3 +348,17 @@ nsThreadManager::GetHighestNumberOfThreads()
OffTheBooksMutexAutoLock lock(mLock);
return mHighestNumberOfThreads;
}
NS_IMETHODIMP
nsThreadManager::DispatchToMainThread(nsIRunnable *aEvent)
{
// Note: C++ callers should instead use NS_DispatchToMainThread.
MOZ_ASSERT(NS_IsMainThread());
// Keep this functioning during Shutdown
if (NS_WARN_IF(!mMainThread)) {
return NS_ERROR_NOT_INITIALIZED;
}
return mMainThread->DispatchFromScript(aEvent, 0);
}