Commit aefae76f authored by nhiroki's avatar nhiroki Committed by Commit bot

Worker: Refine state management of WorkerThread

This CL...

1) introduces ThreadState enum that represents a state of the worker thread,
2) stops accessing |m_globalScope| from the main thread for detecting worker
   thread initialization and instead checks ThreadState,
3) renames |m_started| and |m_terminated| with |m_requestedToStart| and
   |m_requestedToTerminate| in order to emphasize that these fields represent
   not a state of the worker thread but facts that the worker thread has been
   requested to start/terminate from the main thread, and
4) removes mention of |m_microtaskRunner| from a comment about
   |m_threadStateMutex| because the member is accessed only from the worker
   thread.

BUG=638877, 640843

Review-Url: https://codereview.chromium.org/2268183005
Cr-Commit-Position: refs/heads/master@{#414336}
parent 3f789c4c
...@@ -205,13 +205,22 @@ private: ...@@ -205,13 +205,22 @@ private:
ExitCode getExitCodeForTesting(); ExitCode getExitCodeForTesting();
// Accessed only on the main thread. // Accessed only on the main thread.
bool m_started = false; bool m_requestedToStart = false;
// Set on the main thread and checked on both the main and worker threads. // Set on the main thread and checked on both the main and worker threads.
bool m_terminated = false; bool m_requestedToTerminate = false;
// Set on the worker thread and checked on both the main and worker threads. // Represents the state of this worker thread. A caller may need to acquire
bool m_readyToShutdown = false; // 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. // Accessed only on the worker thread.
bool m_pausedInDebugger = false; bool m_pausedInDebugger = false;
...@@ -229,8 +238,8 @@ private: ...@@ -229,8 +238,8 @@ private:
RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; RefPtr<WorkerLoaderProxy> m_workerLoaderProxy;
WorkerReportingProxy& m_workerReportingProxy; WorkerReportingProxy& m_workerReportingProxy;
// This lock protects |m_globalScope|, |m_terminated|, |m_readyToShutdown|, // This lock protects |m_globalScope|, |m_requestedToTerminate|,
// |m_runningDebuggerTask|, |m_exitCode| and |m_microtaskRunner|. // |m_threadState|, |m_runningDebuggerTask| and |m_exitCode|.
Mutex m_threadStateMutex; Mutex m_threadStateMutex;
Persistent<ConsoleMessageStorage> m_consoleMessageStorage; Persistent<ConsoleMessageStorage> m_consoleMessageStorage;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment