Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThread.h

Issue 2325923002: Worker: Factor out a part of WorkerThread::terminateInternal() into its own function for cleanup (Closed)
Patch Set: fix comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/WorkerThread.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/workers/WorkerThread.h
diff --git a/third_party/WebKit/Source/core/workers/WorkerThread.h b/third_party/WebKit/Source/core/workers/WorkerThread.h
index 600f1f968d3e25e94674665f5d5070c0d323ec69..217a1d1cb456b542308437aa2d74a8b1a90f4ee4 100644
--- a/third_party/WebKit/Source/core/workers/WorkerThread.h
+++ b/third_party/WebKit/Source/core/workers/WorkerThread.h
@@ -165,6 +165,7 @@ protected:
private:
friend class WorkerThreadTest;
+ FRIEND_TEST_ALL_PREFIXES(WorkerThreadTest, ShouldScheduleToTerminateExecution);
FRIEND_TEST_ALL_PREFIXES(WorkerThreadTest, StartAndTerminateOnInitialization_TerminateWhileDebuggerTaskIsRunning);
FRIEND_TEST_ALL_PREFIXES(WorkerThreadTest, StartAndTerminateOnScriptLoaded_TerminateWhileDebuggerTaskIsRunning);
@@ -183,7 +184,25 @@ private:
Graceful,
};
+ // Represents the state of this worker thread. A caller may need to acquire
+ // a lock |m_threadStateMutex| before accessing this:
+ // - Only the worker thread can set this with the lock.
+ // - The worker thread can read this without the lock.
+ // - The main thread can read this with the lock.
+ enum class ThreadState {
+ NotStarted,
+ Running,
+ ReadyToShutdown,
+ };
+
void terminateInternal(TerminationMode);
+
+ // Returns true if we should synchronously terminate or schedule to
+ // terminate the worker execution so that a shutdown task can be handled by
+ // the thread event loop. This must be called with |m_threadStateMutex|
+ // acquired.
+ bool shouldScheduleToTerminateExecution(const MutexLocker&);
+
void forciblyTerminateExecution();
// Returns true if termination or shutdown sequence has started. This is
@@ -199,6 +218,11 @@ private:
void performDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>);
void performDebuggerTaskDontWaitOnWorkerThread();
+ // These must be called with |m_threadStateMutex| acquired.
+ void setThreadState(const MutexLocker&, ThreadState);
+ void setExitCode(const MutexLocker&, ExitCode);
+ bool isThreadStateMutexLocked(const MutexLocker&);
+
ExitCode getExitCodeForTesting();
// Accessed only on the main thread.
@@ -207,16 +231,6 @@ private:
// Set on the main thread and checked on both the main and worker threads.
bool m_requestedToTerminate = false;
- // Represents the state of this worker thread. A caller may need to acquire
- // a lock |m_threadStateMutex| before accessing this:
- // - Only the worker thread can set this with the lock.
- // - The worker thread can read this without the lock.
- // - The main thread can read this with the lock.
- enum class ThreadState {
- NotStarted,
- Running,
- ReadyToShutdown,
- };
ThreadState m_threadState = ThreadState::NotStarted;
// Accessed only on the worker thread.
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/WorkerThread.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698