mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1286487 - WorkerProxyToMainThreadRunnable must keep alive workers using WorkerHolder, r=bkelly
This commit is contained in:
parent
602a0147b1
commit
0ba6bcc1bb
@ -677,13 +677,13 @@ WorkerProxyToMainThreadRunnable::Dispatch()
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (NS_WARN_IF(!mWorkerPrivate->ModifyBusyCountFromWorker(true))) {
|
||||
if (NS_WARN_IF(!HoldWorker())) {
|
||||
RunBackOnWorkerThread();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
|
||||
mWorkerPrivate->ModifyBusyCountFromWorker(false);
|
||||
ReleaseWorker();
|
||||
RunBackOnWorkerThread();
|
||||
return false;
|
||||
}
|
||||
@ -733,7 +733,7 @@ WorkerProxyToMainThreadRunnable::PostDispatchOnMainThread()
|
||||
mRunnable->RunBackOnWorkerThread();
|
||||
|
||||
// Let's release the worker thread.
|
||||
aWorkerPrivate->ModifyBusyCountFromWorker(false);
|
||||
mRunnable->ReleaseWorker();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -746,3 +746,37 @@ WorkerProxyToMainThreadRunnable::PostDispatchOnMainThread()
|
||||
new ReleaseRunnable(mWorkerPrivate, this);
|
||||
NS_WARN_IF(!runnable->Dispatch());
|
||||
}
|
||||
|
||||
bool
|
||||
WorkerProxyToMainThreadRunnable::HoldWorker()
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
|
||||
class SimpleWorkerHolder final : public WorkerHolder
|
||||
{
|
||||
public:
|
||||
bool Notify(Status aStatus) override
|
||||
{
|
||||
// We don't care about the notification. We just want to keep the
|
||||
// mWorkerPrivate alive.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
UniquePtr<WorkerHolder> workerHolder(new SimpleWorkerHolder());
|
||||
if (NS_WARN_IF(!workerHolder->HoldWorker(mWorkerPrivate))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mWorkerHolder = Move(workerHolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
WorkerProxyToMainThreadRunnable::ReleaseWorker()
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(mWorkerHolder);
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
|
@ -433,8 +433,12 @@ private:
|
||||
|
||||
void PostDispatchOnMainThread();
|
||||
|
||||
bool HoldWorker();
|
||||
void ReleaseWorker();
|
||||
|
||||
protected:
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
UniquePtr<WorkerHolder> mWorkerHolder;
|
||||
};
|
||||
|
||||
// Class for checking API exposure. This totally violates the "MUST" in the
|
||||
|
Loading…
Reference in New Issue
Block a user