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 192f206027341e9a5ec4eed72d485acfea2120ae..61bbf7f4e735dfb0cc66ff5e0325c4039ffd57bd 100644 |
--- a/third_party/WebKit/Source/core/workers/WorkerThread.h |
+++ b/third_party/WebKit/Source/core/workers/WorkerThread.h |
@@ -62,15 +62,23 @@ enum WorkerThreadStartMode { |
// an actual task is executed on the worker thread. |
class CORE_EXPORT WorkerThread { |
public: |
+ // Represents how this thread is terminated. |
+ enum class ExitCode { |
+ NotTerminated, |
+ TerminatedBeforeStarting, |
+ GracefullyTerminated, |
+ SyncForciblyTerminated, |
+ AsyncForciblyTerminated, |
+ }; |
+ |
virtual ~WorkerThread(); |
// Called on the main thread. |
void start(PassOwnPtr<WorkerThreadStartupData>); |
void terminate(); |
- // Called in shutdown sequence on the main thread. Internally calls |
- // terminate() and wait (by *blocking* the calling thread) until the |
- // worker(s) is/are shut down. |
+ // Called on the main thread. Internally calls terminateInternal() and wait |
+ // (by *blocking* the calling thread) until the worker(s) is/are shut down. |
void terminateAndWait(); |
static void terminateAndWaitForAllWorkers(); |
@@ -114,6 +122,8 @@ public: |
PlatformThreadId platformThreadId(); |
+ ExitCode exitCode(); |
kinuko
2016/05/31 10:13:26
nit: getExitCode()
c.f. "Please use names that di
nhiroki
2016/06/01 04:16:36
Thank you for sharing the pointer. I missed the di
|
+ |
protected: |
WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
@@ -125,22 +135,44 @@ protected: |
virtual void postInitialize() { } |
private: |
+ friend class WorkerThreadTest; |
+ |
+ class ForceTerminationTask; |
class WorkerMicrotaskRunner; |
+ enum class TerminationMode { |
+ // Synchronously terminate the isolate. Please be careful to use this |
kinuko
2016/05/31 10:13:26
nit: "terminate the isolate" -> "terminate the v8
nhiroki
2016/06/01 04:16:36
Replaced all.
|
+ // mode, because after the synchronous termination any V8 APIs may |
+ // suddenly start to return empty handles and it may cause crashes. |
+ Forcible, |
+ |
+ // Don't synchronously terminate the isolate. Instead, schedule a task |
+ // to terminate the isolate in case that the shutdown sequence does not |
+ // start on the worker thread in a certain time period. |
+ Graceful, |
+ }; |
+ |
std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<ExecutionContextTask>, bool isInstrumented); |
void initializeOnWorkerThread(PassOwnPtr<WorkerThreadStartupData>); |
+ void terminateInternal(TerminationMode); |
+ void forciblyTerminateIsolate(); |
kinuko
2016/05/31 10:13:26
nit: why are having these methods between initiali
kinuko
2016/05/31 10:13:26
nit: forciblyTerminateV8Isolate or forciblyTermina
nhiroki
2016/06/01 04:16:36
Done.
nhiroki
2016/06/01 04:16:36
In common cases, these are called after initialize
|
void prepareForShutdownOnWorkerThread(); |
void performShutdownOnWorkerThread(); |
void performTaskOnWorkerThread(std::unique_ptr<ExecutionContextTask>, bool isInstrumented); |
void runDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); |
void runDebuggerTaskDontWaitOnWorkerThread(); |
+ void setForceTerminationDelayInMsForTesting(long long forceTerminationDelayInMs) { m_forceTerminationDelayInMs = forceTerminationDelayInMs; } |
+ |
bool m_started = false; |
bool m_terminated = false; |
bool m_readyToShutdown = false; |
bool m_pausedInDebugger = false; |
bool m_runningDebuggerTask = false; |
+ ExitCode m_exitCode = ExitCode::NotTerminated; |
+ |
+ long long m_forceTerminationDelayInMs; |
OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner; |
OwnPtr<WorkerMicrotaskRunner> m_microtaskRunner; |
@@ -149,7 +181,8 @@ private: |
WorkerReportingProxy& m_workerReportingProxy; |
// This lock protects |m_workerGlobalScope|, |m_terminated|, |
- // |m_readyToShutdown|, |m_runningDebuggerTask| and |m_microtaskRunner|. |
+ // |m_readyToShutdown|, |m_runningDebuggerTask|, |m_exitCode| and |
+ // |m_microtaskRunner|. |
Mutex m_threadStateMutex; |
Persistent<WorkerGlobalScope> m_workerGlobalScope; |
@@ -159,6 +192,10 @@ private: |
// Signaled when the thread completes termination on the worker thread. |
OwnPtr<WaitableEvent> m_shutdownEvent; |
+ |
+ // Scheduled when termination starts with TerminationMode::Force, and |
+ // cancelled when the worker thread is gracefully shut down. |
+ OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask; |
}; |
} // namespace blink |