diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 6f7f8f1ed222..48c7927eaf79 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1606,14 +1606,14 @@ class OffThreadCompilationCompleteTask : public Task { } #endif - bool Run() override { + TaskResult Run() override { MOZ_ASSERT(NS_IsMainThread()); RefPtr context = mRequest->GetScriptLoadContext(); if (!context->mCompileOrDecodeTask) { // Request has been cancelled by MaybeCancelOffThreadScript. - return true; + return TaskResult::Complete; } RecordStopTime(); @@ -1638,7 +1638,7 @@ class OffThreadCompilationCompleteTask : public Task { mRequest = nullptr; mLoader = nullptr; - return true; + return TaskResult::Complete; } private: @@ -1857,17 +1857,17 @@ class ScriptOrModuleCompileTask final : public CompileOrDecodeTask { return NS_OK; } - bool Run() override { + TaskResult Run() override { MutexAutoLock lock(mMutex); if (IsCancelled(lock)) { - return true; + return TaskResult::Complete; } RefPtr stencil = Compile(); DidRunTask(lock, std::move(stencil)); - return true; + return TaskResult::Complete; } private: @@ -1932,11 +1932,11 @@ class ScriptDecodeTask final : public CompileOrDecodeTask { return NS_OK; } - bool Run() override { + TaskResult Run() override { MutexAutoLock lock(mMutex); if (IsCancelled(lock)) { - return true; + return TaskResult::Complete; } RefPtr stencil = Decode(); @@ -1946,7 +1946,7 @@ class ScriptDecodeTask final : public CompileOrDecodeTask { mOptions.steal(std::move(mDecodeOptions)); DidRunTask(lock, std::move(stencil)); - return true; + return TaskResult::Complete; } private: diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 9347c7f99093..92ffafc559b2 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -1885,9 +1885,9 @@ class ScriptCompileTask final : public Task { } public: - bool Run() override { + TaskResult Run() override { Compile(); - return true; + return TaskResult::Complete; } already_AddRefed StealStencil() { return mStencil.forget(); } @@ -1923,11 +1923,11 @@ class NotifyOffThreadScriptCompletedTask : public Task { mReceiver(aReceiver), mCompileTask(aCompileTask) {} - bool Run() override { + TaskResult Run() override { MOZ_ASSERT(NS_IsMainThread()); if (PastShutdownPhase(ShutdownPhase::XPCOMShutdownFinal)) { - return true; + return TaskResult::Complete; } RefPtr stencil = mCompileTask->StealStencil(); @@ -1936,7 +1936,7 @@ class NotifyOffThreadScriptCompletedTask : public Task { (void)mReceiver->OnScriptCompileComplete( stencil, stencil ? NS_OK : NS_ERROR_FAILURE); - return true; + return TaskResult::Complete; } #ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index 2781bcc5a314..b63322691452 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -142,9 +142,9 @@ class DecodingTask final : public Task { : EventQueuePriority::RenderBlocking), mTask(aTask) {} - bool Run() override { + TaskResult Run() override { mTask->Run(); - return true; + return TaskResult::Complete; } #ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY diff --git a/js/xpconnect/loader/ChromeScriptLoader.cpp b/js/xpconnect/loader/ChromeScriptLoader.cpp index 354aac1d02c2..78bb512187ad 100644 --- a/js/xpconnect/loader/ChromeScriptLoader.cpp +++ b/js/xpconnect/loader/ChromeScriptLoader.cpp @@ -143,15 +143,15 @@ class AsyncScriptCompileTask final : public Task { } public: - bool Run() override { + TaskResult Run() override { MutexAutoLock lock(mMutex); if (mIsCancelled) { - return true; + return TaskResult::Complete; } Compile(); - return true; + return TaskResult::Complete; } already_AddRefed StealStencil(JSContext* aCx) { @@ -227,7 +227,7 @@ class AsyncScriptCompilationCompleteTask : public Task { } #endif - bool Run() override; + TaskResult Run() override; private: // NOTE: @@ -379,11 +379,11 @@ bool AsyncScriptCompiler::StartOffThreadCompile( return true; } -bool AsyncScriptCompilationCompleteTask::Run() { +Task::TaskResult AsyncScriptCompilationCompleteTask::Run() { mCompiler->OnCompilationComplete(mCompileTask.get()); mCompiler = nullptr; mCompileTask = nullptr; - return true; + return TaskResult::Complete; } void AsyncScriptCompiler::OnCompilationComplete( diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 9b5fcd84127c..e1e5a7ecef54 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -1165,9 +1165,9 @@ CycleCollectedJSRuntime* XPCJSContext::CreateRuntime(JSContext* aCx) { class HelperThreadTaskHandler : public Task { public: - bool Run() override { + TaskResult Run() override { JS::RunHelperThreadTask(); - return true; + return TaskResult::Complete; } explicit HelperThreadTaskHandler() : Task(Kind::OffMainThreadOnly, EventQueuePriority::Normal) { diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index a1722c08e96e..118766bfea95 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -608,17 +608,17 @@ class InitializeVirtualDesktopManagerTask : public Task { } #endif - virtual bool Run() override { + virtual TaskResult Run() override { RefPtr desktopManager; HRESULT hr = ::CoCreateInstance( CLSID_VirtualDesktopManager, NULL, CLSCTX_INPROC_SERVER, __uuidof(IVirtualDesktopManager), getter_AddRefs(desktopManager)); if (FAILED(hr)) { - return true; + return TaskResult::Complete; } gVirtualDesktopManager = desktopManager; - return true; + return TaskResult::Complete; } }; @@ -2185,13 +2185,13 @@ void nsWindow::AsyncUpdateWorkspaceID(Desktop& aDesktop) { : Task(Kind::OffMainThreadOnly, EventQueuePriority::Normal), mSelf(aSelf) {} - bool Run() override { + TaskResult Run() override { auto desktop = mSelf->mDesktopId.Lock(); if (desktop->mUpdateIsQueued) { DoGetWorkspaceID(mSelf->mWnd, &desktop->mID); desktop->mUpdateIsQueued = false; } - return true; + return TaskResult::Complete; } #ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY diff --git a/xpcom/threads/IdleTaskRunner.cpp b/xpcom/threads/IdleTaskRunner.cpp index 2a61877fa050..d1a571d089a7 100644 --- a/xpcom/threads/IdleTaskRunner.cpp +++ b/xpcom/threads/IdleTaskRunner.cpp @@ -36,7 +36,7 @@ class IdleTaskRunnerTask : public Task { SetManager(TaskController::Get()->GetIdleTaskManager()); } - bool Run() override { + TaskResult Run() override { if (mRunner) { // IdleTaskRunner::Run can actually trigger the destruction of the // IdleTaskRunner. Make sure it doesn't get destroyed before the method @@ -44,7 +44,7 @@ class IdleTaskRunnerTask : public Task { RefPtr runner(mRunner); runner->Run(); } - return true; + return TaskResult::Complete; } void SetIdleDeadline(TimeStamp aDeadline) override { diff --git a/xpcom/threads/TaskController.cpp b/xpcom/threads/TaskController.cpp index c617f43217ed..0bf7d3160a4a 100644 --- a/xpcom/threads/TaskController.cpp +++ b/xpcom/threads/TaskController.cpp @@ -344,7 +344,7 @@ void TaskController::RunPoolThread() { MutexAutoUnlock unlock(mGraphMutex); lastTask = nullptr; AUTO_PROFILE_FOLLOWING_TASK(task); - taskCompleted = task->Run(); + taskCompleted = task->Run() == Task::TaskResult::Complete; ranTask = true; } @@ -545,10 +545,10 @@ class RunnableTask : public Task { Kind aKind) : Task(aKind, aPriority), mRunnable(aRunnable) {} - virtual bool Run() override { + virtual TaskResult Run() override { mRunnable->Run(); mRunnable = nullptr; - return true; + return TaskResult::Complete; } void SetIdleDeadline(TimeStamp aDeadline) override { @@ -873,7 +873,7 @@ bool TaskController::DoExecuteNextTaskOnlyMainThreadInternal( AutoSetMainThreadRunnableName nameGuard(name); #endif AUTO_PROFILE_FOLLOWING_TASK(task); - result = task->Run(); + result = task->Run() == Task::TaskResult::Complete; } // Task itself should keep manager alive. diff --git a/xpcom/threads/TaskController.h b/xpcom/threads/TaskController.h index 5293604898bb..f51e61f4cd65 100644 --- a/xpcom/threads/TaskController.h +++ b/xpcom/threads/TaskController.h @@ -203,9 +203,14 @@ class Task { friend class TaskController; - // When this returns false, the task is considered incomplete and will be - // rescheduled at the current 'mPriority' level. - virtual bool Run() = 0; + enum class TaskResult { + Complete, + Incomplete, + }; + + // When this returns TaskResult::Incomplete, it will be rescheduled at the + // current 'mPriority' level. + virtual TaskResult Run() = 0; private: Task* GetHighestPriorityDependency();