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 92c7dbe30e5e2029efd02695376b526fe3649d85..7a750c6132acce3292f82d8cb59e10ec20d8afa4 100644 |
--- a/third_party/WebKit/Source/core/workers/WorkerThread.h |
+++ b/third_party/WebKit/Source/core/workers/WorkerThread.h |
@@ -32,6 +32,7 @@ |
#include "core/frame/csp/ContentSecurityPolicy.h" |
#include "core/workers/WorkerGlobalScope.h" |
#include "core/workers/WorkerLoaderProxy.h" |
+#include "core/workers/WorkerOrWorkletThread.h" |
#include "wtf/Forward.h" |
#include "wtf/Functional.h" |
#include "wtf/OwnPtr.h" |
@@ -48,11 +49,6 @@ class WorkerInspectorController; |
class WorkerReportingProxy; |
class WorkerThreadStartupData; |
-enum WorkerThreadStartMode { |
- DontPauseWorkerGlobalScopeOnStart, |
- PauseWorkerGlobalScopeOnStart |
-}; |
- |
// WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism |
// can access the lower thread infrastructure via an implementation of this |
// abstract class. Multiple WorkerThreads can share one WorkerBackingThread. |
@@ -60,37 +56,10 @@ enum WorkerThreadStartMode { |
// |
// WorkerThread start and termination must be initiated on the main thread and |
// an actual task is executed on the worker thread. |
-class CORE_EXPORT WorkerThread { |
+class CORE_EXPORT WorkerThread : public WorkerOrWorkletThread { |
public: |
- // Represents how this thread is terminated. |
- enum class ExitCode { |
- NotTerminated, |
- GracefullyTerminated, |
- SyncForciblyTerminated, |
- AsyncForciblyTerminated, |
- }; |
- |
- virtual ~WorkerThread(); |
- |
// Called on the main thread. |
void start(PassOwnPtr<WorkerThreadStartupData>); |
- void terminate(); |
- |
- // 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(); |
- |
- virtual WorkerBackingThread& workerBackingThread() = 0; |
- virtual bool shouldAttachThreadDebugger() const { return true; } |
- v8::Isolate* isolate(); |
- |
- // Can be used to wait for this worker thread to terminate. |
- // (This is signaled on the main thread, so it's assumed to be waited on |
- // the worker context thread) |
- WaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
- |
- bool isCurrentThread(); |
WorkerLoaderProxy* workerLoaderProxy() const |
{ |
@@ -98,104 +67,21 @@ public: |
return m_workerLoaderProxy.get(); |
} |
- WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; } |
- |
- void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask>); |
- void appendDebuggerTask(std::unique_ptr<CrossThreadClosure>); |
- |
- // Runs only debugger tasks while paused in debugger, called on the worker |
- // thread. |
- void startRunningDebuggerTasksOnPause(); |
- void stopRunningDebuggerTasksOnPause(); |
- bool isRunningDebuggerTasksOnPause() const { return m_pausedInDebugger; } |
- |
- // Can be called only on the worker thread, WorkerGlobalScope is not thread |
- // safe. |
- WorkerGlobalScope* workerGlobalScope(); |
- |
- // Returns true once one of the terminate* methods is called. |
- bool terminated(); |
- |
- // Number of active worker threads. |
- static unsigned workerThreadCount(); |
- |
- PlatformThreadId platformThreadId(); |
- |
- ExitCode getExitCode(); |
+ // Factory method for creating a new worker context for the thread. |
+ // Called on the worker thread. |
+ virtual WorkerGlobalScope* createWorkerGlobalScope(WorkerThreadStartupData*) = 0; |
protected: |
WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
- // Factory method for creating a new worker context for the thread. |
- // Called on the worker thread. |
- virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadStartupData>) = 0; |
- |
// Called on the worker thread. |
virtual void postInitialize() { } |
private: |
friend class WorkerThreadTest; |
- class ForceTerminationTask; |
- class WorkerMicrotaskRunner; |
- |
- enum class TerminationMode { |
- // Synchronously terminate the worker execution. Please be careful to |
- // use this 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 worker execution. Instead, schedule |
- // a task to terminate it 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 terminateInternal(TerminationMode); |
- void forciblyTerminateExecution(); |
- |
void initializeOnWorkerThread(PassOwnPtr<WorkerThreadStartupData>); |
- 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; |
- |
RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
- WorkerReportingProxy& m_workerReportingProxy; |
- |
- // This lock protects |m_workerGlobalScope|, |m_terminated|, |
- // |m_readyToShutdown|, |m_runningDebuggerTask|, |m_exitCode| and |
- // |m_microtaskRunner|. |
- Mutex m_threadStateMutex; |
- |
- Persistent<WorkerGlobalScope> m_workerGlobalScope; |
- |
- // Signaled when the thread starts termination on the main thread. |
- OwnPtr<WaitableEvent> m_terminationEvent; |
- |
- // 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 |