diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 5f082b804973..12cf5bfa2857 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1744,19 +1744,16 @@ WorkerPrivateParent::MaybeWrapAsWorkerRunnable(already_AddRefed bool -WorkerPrivateParent::Start() +WorkerPrivate::Start() { // May be called on any thread! { MutexAutoLock lock(mMutex); - WorkerPrivate* self = ParentAsWorkerPrivate(); + NS_ASSERTION(mParentStatus != Running, "How can this be?!"); - NS_ASSERTION(self->mParentStatus != Running, "How can this be?!"); - - if (self->mParentStatus == Pending) { - self->mParentStatus = Running; + if (mParentStatus == Pending) { + mParentStatus = Running; return true; } } @@ -1765,30 +1762,28 @@ WorkerPrivateParent::Start() } // aCx is null when called from the finalizer -template bool -WorkerPrivateParent::NotifyPrivate(WorkerStatus aStatus) +WorkerPrivate::NotifyPrivate(WorkerStatus aStatus) { AssertIsOnParentThread(); - WorkerPrivate* self = ParentAsWorkerPrivate(); bool pending; { MutexAutoLock lock(mMutex); - if (self->mParentStatus >= aStatus) { + if (mParentStatus >= aStatus) { return true; } - pending = self->mParentStatus == Pending; - self->mParentStatus = aStatus; + pending = mParentStatus == Pending; + mParentStatus = aStatus; } - if (self->IsSharedWorker()) { + if (IsSharedWorker()) { RuntimeService* runtime = RuntimeService::GetService(); MOZ_ASSERT(runtime); - runtime->ForgetSharedWorker(ParentAsWorkerPrivate()); + runtime->ForgetSharedWorker(this); } if (pending) { @@ -1799,25 +1794,24 @@ WorkerPrivateParent::NotifyPrivate(WorkerStatus aStatus) nsIThread* currentThread = NS_GetCurrentThread(); MOZ_ASSERT(currentThread); - MOZ_ASSERT(!self->mPRThread); - self->mPRThread = PRThreadFromThread(currentThread); - MOZ_ASSERT(self->mPRThread); + MOZ_ASSERT(!mPRThread); + mPRThread = PRThreadFromThread(currentThread); + MOZ_ASSERT(mPRThread); } #endif // Worker never got a chance to run, go ahead and delete it. - self->ScheduleDeletion(WorkerPrivate::WorkerNeverRan); + ScheduleDeletion(WorkerPrivate::WorkerNeverRan); return true; } - NS_ASSERTION(aStatus != Terminating || self->mQueuedRunnables.IsEmpty(), + NS_ASSERTION(aStatus != Terminating || mQueuedRunnables.IsEmpty(), "Shouldn't have anything queued!"); // Anything queued will be discarded. - self->mQueuedRunnables.Clear(); + mQueuedRunnables.Clear(); - RefPtr runnable = - new NotifyRunnable(ParentAsWorkerPrivate(), aStatus); + RefPtr runnable = new NotifyRunnable(this, aStatus); return runnable->Dispatch(); } @@ -1989,15 +1983,12 @@ WorkerPrivate::ParentWindowResumed() } } -template bool -WorkerPrivateParent::Close() +WorkerPrivate::Close() { mMutex.AssertCurrentThreadOwns(); - WorkerPrivate* self = ParentAsWorkerPrivate(); - - if (self->mParentStatus < Closing) { - self->mParentStatus = Closing; + if (mParentStatus < Closing) { + mParentStatus = Closing; } return true; diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index ea7f31506288..8741bc04c5c7 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -143,15 +143,6 @@ private: return static_cast(const_cast(this)); } - bool - NotifyPrivate(WorkerStatus aStatus); - - bool - TerminatePrivate() - { - return NotifyPrivate(Terminating); - } - public: NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent) @@ -167,39 +158,6 @@ public: already_AddRefed MaybeWrapAsWorkerRunnable(already_AddRefed aRunnable); - // May be called on any thread... - bool - Start(); - - // Called on the parent thread. - bool - Notify(WorkerStatus aStatus) - { - return NotifyPrivate(aStatus); - } - - bool - Cancel() - { - return Notify(Canceling); - } - - bool - Kill() - { - return Notify(Killing); - } - - bool - Terminate() - { - AssertIsOnParentThread(); - return TerminatePrivate(); - } - - bool - Close(); - bool ProxyReleaseMainThreadObjects(); @@ -471,6 +429,39 @@ public: mSelfRef = nullptr; } + // May be called on any thread... + bool + Start(); + + // Called on the parent thread. + bool + Notify(WorkerStatus aStatus) + { + return NotifyPrivate(aStatus); + } + + bool + Cancel() + { + return Notify(Canceling); + } + + bool + Kill() + { + return Notify(Killing); + } + + bool + Terminate() + { + AssertIsOnParentThread(); + return TerminatePrivate(); + } + + bool + Close(); + // The passed principal must be the Worker principal in case of a // ServiceWorker and the loading principal for any other type. static void @@ -1402,6 +1393,15 @@ private: DispatchPrivate(already_AddRefed aRunnable, nsIEventTarget* aSyncLoopTarget); + bool + NotifyPrivate(WorkerStatus aStatus); + + bool + TerminatePrivate() + { + return NotifyPrivate(Terminating); + } + bool MayContinueRunning() {