Skip to content

Commit

Permalink
Bug 1846407 - Use enum class for Task::Run return value. r=bas,win-re…
Browse files Browse the repository at this point in the history
…viewers,rkraesig

Differential Revision: https://phabricator.services.mozilla.com/D185043
  • Loading branch information
arai-a committed Oct 18, 2023
1 parent e63c54d commit 0054ab3
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 36 deletions.
18 changes: 9 additions & 9 deletions dom/script/ScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,14 +1606,14 @@ class OffThreadCompilationCompleteTask : public Task {
}
#endif

bool Run() override {
TaskResult Run() override {
MOZ_ASSERT(NS_IsMainThread());

RefPtr<ScriptLoadContext> context = mRequest->GetScriptLoadContext();

if (!context->mCompileOrDecodeTask) {
// Request has been cancelled by MaybeCancelOffThreadScript.
return true;
return TaskResult::Complete;
}

RecordStopTime();
Expand All @@ -1638,7 +1638,7 @@ class OffThreadCompilationCompleteTask : public Task {

mRequest = nullptr;
mLoader = nullptr;
return true;
return TaskResult::Complete;
}

private:
Expand Down Expand Up @@ -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<JS::Stencil> stencil = Compile();

DidRunTask(lock, std::move(stencil));
return true;
return TaskResult::Complete;
}

private:
Expand Down Expand Up @@ -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<JS::Stencil> stencil = Decode();
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions dom/xul/nsXULElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,9 +1885,9 @@ class ScriptCompileTask final : public Task {
}

public:
bool Run() override {
TaskResult Run() override {
Compile();
return true;
return TaskResult::Complete;
}

already_AddRefed<JS::Stencil> StealStencil() { return mStencil.forget(); }
Expand Down Expand Up @@ -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<JS::Stencil> stencil = mCompileTask->StealStencil();
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions image/DecodePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions js/xpconnect/loader/ChromeScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<JS::Stencil> StealStencil(JSContext* aCx) {
Expand Down Expand Up @@ -227,7 +227,7 @@ class AsyncScriptCompilationCompleteTask : public Task {
}
#endif

bool Run() override;
TaskResult Run() override;

private:
// NOTE:
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions js/xpconnect/src/XPCJSContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,17 +608,17 @@ class InitializeVirtualDesktopManagerTask : public Task {
}
#endif

virtual bool Run() override {
virtual TaskResult Run() override {
RefPtr<IVirtualDesktopManager> 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;
}
};

Expand Down
4 changes: 2 additions & 2 deletions xpcom/threads/IdleTaskRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ 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
// finished.
RefPtr<IdleTaskRunner> runner(mRunner);
runner->Run();
}
return true;
return TaskResult::Complete;
}

void SetIdleDeadline(TimeStamp aDeadline) override {
Expand Down
8 changes: 4 additions & 4 deletions xpcom/threads/TaskController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions xpcom/threads/TaskController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0054ab3

Please sign in to comment.