Bug 1268231 - Get rid of StopSyncLoopRunnable, r=khuey

This commit is contained in:
Andrea Marchesini 2016-05-03 10:21:59 +02:00
Родитель 0fdab8e9ee
Коммит 6bf6e9c639
2 изменённых файлов: 22 добавлений и 40 удалений

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

@ -467,19 +467,20 @@ MainThreadWorkerSyncRunnable::PostDispatch(WorkerPrivate* aWorkerPrivate,
{
}
StopSyncLoopRunnable::StopSyncLoopRunnable(
MainThreadStopSyncLoopRunnable::MainThreadStopSyncLoopRunnable(
WorkerPrivate* aWorkerPrivate,
already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
bool aResult)
: WorkerSyncRunnable(aWorkerPrivate, Move(aSyncLoopTarget)), mResult(aResult)
{
AssertIsOnMainThread();
#ifdef DEBUG
mWorkerPrivate->AssertValidSyncLoop(mSyncLoopTarget);
#endif
}
nsresult
StopSyncLoopRunnable::Cancel()
MainThreadStopSyncLoopRunnable::Cancel()
{
nsresult rv = Run();
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Run() failed");
@ -491,8 +492,8 @@ StopSyncLoopRunnable::Cancel()
}
bool
StopSyncLoopRunnable::WorkerRun(JSContext* aCx,
WorkerPrivate* aWorkerPrivate)
MainThreadStopSyncLoopRunnable::WorkerRun(JSContext* aCx,
WorkerPrivate* aWorkerPrivate)
{
aWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mSyncLoopTarget);
@ -509,11 +510,11 @@ StopSyncLoopRunnable::WorkerRun(JSContext* aCx,
}
bool
StopSyncLoopRunnable::DispatchInternal()
MainThreadStopSyncLoopRunnable::DispatchInternal()
{
MOZ_ASSERT(mSyncLoopTarget);
RefPtr<StopSyncLoopRunnable> runnable(this);
RefPtr<MainThreadStopSyncLoopRunnable> runnable(this);
return NS_SUCCEEDED(mSyncLoopTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL));
}

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

@ -264,18 +264,20 @@ private:
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override;
};
// This runnable is used to stop a sync loop . As sync loops keep the busy count
// incremented as long as they run this runnable does not modify the busy count
// This runnable is used to stop a sync loop and it's meant to be used on the
// main-thread only. As sync loops keep the busy count incremented as long as
// they run this runnable does not modify the busy count
// in any way.
class StopSyncLoopRunnable : public WorkerSyncRunnable
class MainThreadStopSyncLoopRunnable : public WorkerSyncRunnable
{
bool mResult;
public:
// Passing null for aSyncLoopTarget is not allowed.
StopSyncLoopRunnable(WorkerPrivate* aWorkerPrivate,
already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
bool aResult);
MainThreadStopSyncLoopRunnable(
WorkerPrivate* aWorkerPrivate,
already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
bool aResult);
// By default StopSyncLoopRunnables cannot be canceled since they could leave
// a sync loop spinning forever.
@ -283,7 +285,7 @@ public:
Cancel() override;
protected:
virtual ~StopSyncLoopRunnable()
virtual ~MainThreadStopSyncLoopRunnable()
{ }
// Called on the worker thread, in WorkerRun, right before stopping the
@ -296,33 +298,6 @@ protected:
MaybeSetException()
{ }
private:
virtual bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
virtual bool
DispatchInternal() override final;
};
// This runnable is identical to StopSyncLoopRunnable except it is meant to be
// used on the main thread only.
class MainThreadStopSyncLoopRunnable : public StopSyncLoopRunnable
{
public:
// Passing null for aSyncLoopTarget is not allowed.
MainThreadStopSyncLoopRunnable(
WorkerPrivate* aWorkerPrivate,
already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
bool aResult)
: StopSyncLoopRunnable(aWorkerPrivate, Move(aSyncLoopTarget), aResult)
{
AssertIsOnMainThread();
}
protected:
virtual ~MainThreadStopSyncLoopRunnable()
{ }
private:
virtual bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override final
@ -333,6 +308,12 @@ private:
virtual void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override;
virtual bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
virtual bool
DispatchInternal() override final;
};
// This runnable is processed as soon as it is received by the worker,