mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1153370 - Make mRunningThread atomic and manage it in AutoTaskGuard. r=jww
This commit is contained in:
parent
a4a17224a0
commit
8557ff650d
@ -219,7 +219,6 @@ MediaTaskQueue::IsEmpty()
|
||||
bool
|
||||
MediaTaskQueue::IsCurrentThreadIn()
|
||||
{
|
||||
MonitorAutoLock mon(mQueueMonitor);
|
||||
bool in = NS_GetCurrentThread() == mRunningThread;
|
||||
MOZ_ASSERT_IF(in, GetCurrentQueue() == this);
|
||||
return in;
|
||||
@ -232,7 +231,6 @@ MediaTaskQueue::Runner::Run()
|
||||
{
|
||||
MonitorAutoLock mon(mQueue->mQueueMonitor);
|
||||
MOZ_ASSERT(mQueue->mIsRunning);
|
||||
mQueue->mRunningThread = NS_GetCurrentThread();
|
||||
if (mQueue->mTasks.size() == 0) {
|
||||
mQueue->mIsRunning = false;
|
||||
mQueue->mShutdownPromise.ResolveIfExists(true, __func__);
|
||||
@ -268,7 +266,6 @@ MediaTaskQueue::Runner::Run()
|
||||
mQueue->mIsRunning = false;
|
||||
mQueue->mShutdownPromise.ResolveIfExists(true, __func__);
|
||||
mon.NotifyAll();
|
||||
mQueue->mRunningThread = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
@ -291,7 +288,6 @@ MediaTaskQueue::Runner::Run()
|
||||
mQueue->mIsShutdown = true;
|
||||
mon.NotifyAll();
|
||||
}
|
||||
mQueue->mRunningThread = nullptr;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -302,13 +298,8 @@ void
|
||||
TaskDispatcher::AssertIsTailDispatcherIfRequired()
|
||||
{
|
||||
MediaTaskQueue* currentQueue = MediaTaskQueue::GetCurrentQueue();
|
||||
|
||||
// NB: Make sure not to use the TailDispatcher() accessor, since that
|
||||
// asserts IsCurrentThreadIn(), which acquires the queue monitor, which
|
||||
// triggers a deadlock during shutdown between the queue monitor and the
|
||||
// MediaPromise monitor.
|
||||
MOZ_ASSERT_IF(currentQueue && currentQueue->RequiresTailDispatch(),
|
||||
this == currentQueue->mTailDispatcher);
|
||||
this == ¤tQueue->TailDispatcher());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
bool IsEmpty();
|
||||
|
||||
// Returns true if the current thread is currently running a Runnable in
|
||||
// the task queue. This is for debugging/validation purposes only.
|
||||
// the task queue.
|
||||
bool IsCurrentThreadIn() override;
|
||||
|
||||
protected:
|
||||
@ -141,7 +141,12 @@ protected:
|
||||
// The thread currently running the task queue. We store a reference
|
||||
// to this so that IsCurrentThreadIn() can tell if the current thread
|
||||
// is the thread currently running in the task queue.
|
||||
RefPtr<nsIThread> mRunningThread;
|
||||
//
|
||||
// This may be read on any thread, but may only be written on mRunningThread.
|
||||
// The thread can't die while we're running in it, and we only use it for
|
||||
// pointer-comparison with the current thread anyway - so we make it atomic
|
||||
// and don't refcount it.
|
||||
Atomic<nsIThread*> mRunningThread;
|
||||
|
||||
// RAII class that gets instantiated for each dispatched task.
|
||||
class AutoTaskGuard : public AutoTaskDispatcher
|
||||
@ -157,10 +162,15 @@ protected:
|
||||
MOZ_ASSERT(sCurrentQueueTLS.get() == nullptr);
|
||||
sCurrentQueueTLS.set(aQueue);
|
||||
|
||||
MOZ_ASSERT(mQueue->mRunningThread == nullptr);
|
||||
mQueue->mRunningThread = NS_GetCurrentThread();
|
||||
}
|
||||
|
||||
~AutoTaskGuard()
|
||||
{
|
||||
MOZ_ASSERT(mQueue->mRunningThread == NS_GetCurrentThread());
|
||||
mQueue->mRunningThread = nullptr;
|
||||
|
||||
sCurrentQueueTLS.set(nullptr);
|
||||
mQueue->mTailDispatcher = nullptr;
|
||||
}
|
||||
@ -169,7 +179,6 @@ protected:
|
||||
MediaTaskQueue* mQueue;
|
||||
};
|
||||
|
||||
friend class TaskDispatcher;
|
||||
TaskDispatcher* mTailDispatcher;
|
||||
|
||||
// True if we've dispatched an event to the pool to execute events from
|
||||
|
Loading…
Reference in New Issue
Block a user