зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1435263 - Get rid of WorkerPrivateParent template - part 13 - Start/Close/Kill/Terminate, r=bkelly
This commit is contained in:
Родитель
80346a9dd6
Коммит
67ce33a460
|
@ -1744,19 +1744,16 @@ WorkerPrivateParent<Derived>::MaybeWrapAsWorkerRunnable(already_AddRefed<nsIRunn
|
|||
return workerRunnable.forget();
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
bool
|
||||
WorkerPrivateParent<Derived>::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<Derived>::Start()
|
|||
}
|
||||
|
||||
// aCx is null when called from the finalizer
|
||||
template <class Derived>
|
||||
bool
|
||||
WorkerPrivateParent<Derived>::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<Derived>::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<NotifyRunnable> runnable =
|
||||
new NotifyRunnable(ParentAsWorkerPrivate(), aStatus);
|
||||
RefPtr<NotifyRunnable> runnable = new NotifyRunnable(this, aStatus);
|
||||
return runnable->Dispatch();
|
||||
}
|
||||
|
||||
|
@ -1989,15 +1983,12 @@ WorkerPrivate::ParentWindowResumed()
|
|||
}
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
bool
|
||||
WorkerPrivateParent<Derived>::Close()
|
||||
WorkerPrivate::Close()
|
||||
{
|
||||
mMutex.AssertCurrentThreadOwns();
|
||||
WorkerPrivate* self = ParentAsWorkerPrivate();
|
||||
|
||||
if (self->mParentStatus < Closing) {
|
||||
self->mParentStatus = Closing;
|
||||
if (mParentStatus < Closing) {
|
||||
mParentStatus = Closing;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -143,15 +143,6 @@ private:
|
|||
return static_cast<Derived*>(const_cast<WorkerPrivateParent*>(this));
|
||||
}
|
||||
|
||||
bool
|
||||
NotifyPrivate(WorkerStatus aStatus);
|
||||
|
||||
bool
|
||||
TerminatePrivate()
|
||||
{
|
||||
return NotifyPrivate(Terminating);
|
||||
}
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent)
|
||||
|
||||
|
@ -167,39 +158,6 @@ public:
|
|||
already_AddRefed<WorkerRunnable>
|
||||
MaybeWrapAsWorkerRunnable(already_AddRefed<nsIRunnable> 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<WorkerRunnable> aRunnable,
|
||||
nsIEventTarget* aSyncLoopTarget);
|
||||
|
||||
bool
|
||||
NotifyPrivate(WorkerStatus aStatus);
|
||||
|
||||
bool
|
||||
TerminatePrivate()
|
||||
{
|
||||
return NotifyPrivate(Terminating);
|
||||
}
|
||||
|
||||
bool
|
||||
MayContinueRunning()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче