Index: Source/core/workers/WorkerThread.h |
diff --git a/Source/core/workers/WorkerThread.h b/Source/core/workers/WorkerThread.h |
index 2dccd35e0ef97c02496a1b0fbd1cd4b56e8d8264..deb0028e77ccda3d21b431cfbdad5558145386a4 100644 |
--- a/Source/core/workers/WorkerThread.h |
+++ b/Source/core/workers/WorkerThread.h |
@@ -27,14 +27,10 @@ |
#ifndef WorkerThread_h |
#define WorkerThread_h |
-#include "core/dom/ExecutionContextTask.h" |
#include "core/frame/csp/ContentSecurityPolicy.h" |
-#include "core/workers/WorkerGlobalScope.h" |
-#include "platform/SharedTimer.h" |
+#include "core/workers/WorkerRunLoop.h" |
#include "platform/weborigin/SecurityOrigin.h" |
-#include "public/platform/WebThread.h" |
#include "wtf/Forward.h" |
-#include "wtf/MessageQueue.h" |
#include "wtf/OwnPtr.h" |
#include "wtf/PassRefPtr.h" |
#include "wtf/RefCounted.h" |
@@ -47,49 +43,39 @@ |
class KURL; |
class WorkerGlobalScope; |
- class WorkerInspectorController; |
class WorkerLoaderProxy; |
class WorkerReportingProxy; |
- class WorkerSharedTimer; |
- class WorkerThreadShutdownFinishTask; |
class WorkerThreadStartupData; |
- class WorkerThreadTask; |
+ class WorkerInspectorController; |
enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerGlobalScopeOnStart }; |
- |
class WorkerThread : public RefCounted<WorkerThread> { |
public: |
virtual ~WorkerThread(); |
- virtual void start(); |
- virtual void stop(); |
+ bool start(); |
+ void stop(); |
// Can be used to wait for this worker thread to shut down. |
// (This is signalled on the main thread, so it's assumed to be waited on the worker context thread) |
blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
bool isCurrentThread() const; |
+ WorkerRunLoop& runLoop() { return m_runLoop; } |
WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProxy; } |
WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; } |
void postTask(PassOwnPtr<ExecutionContextTask>); |
void postDebuggerTask(PassOwnPtr<ExecutionContextTask>); |
- enum WaitMode { WaitForMessage, DontWaitForMessage }; |
- MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); |
- |
- // These methods should be called if the holder of the thread is |
- // going to call runDebuggerTask in a loop. |
- void willEnterNestedLoop(); |
- void didLeaveNestedLoop(); |
- |
- blink::WebThread* webThread() { return m_thread.get(); } |
- WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.get(); } |
- bool terminated() const { return m_terminated; } |
+ MessageQueueWaitResult runDebuggerTask(WorkerRunLoop::WaitMode = WorkerRunLoop::WaitForMessage); |
+ bool terminated() { return m_runLoop.terminated(); } |
// Number of active worker threads. |
static unsigned workerThreadCount(); |
+ |
+ WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(); } |
void interruptAndDispatchInspectorCommands(); |
void setWorkerInspectorController(WorkerInspectorController*); |
@@ -100,31 +86,27 @@ |
// Factory method for creating a new worker context for the thread. |
virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
- virtual void postInitialize() { } |
+ // Executes the event loop for the worker thread. Derived classes can override to perform actions before/after entering the event loop. |
+ virtual void runEventLoop(); |
private: |
- friend class WorkerThreadShutdownFinishTask; |
+ // Static function executed as the core routine on the new thread. Passed a pointer to a WorkerThread object. |
+ static void workerThreadStart(void*); |
- void initialize(); |
- void cleanup(); |
- void idleHandler(); |
+ void workerThread(); |
- bool m_terminated; |
- OwnPtr<blink::WebThread> m_thread; |
- OwnPtr<WorkerSharedTimer> m_sharedTimer; |
- MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; |
- |
+ ThreadIdentifier m_threadID; |
+ WorkerRunLoop m_runLoop; |
WorkerLoaderProxy& m_workerLoaderProxy; |
WorkerReportingProxy& m_workerReportingProxy; |
+ |
+ RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
+ Mutex m_threadCreationMutex; |
RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorController; |
Mutex m_workerInspectorControllerMutex; |
- Mutex m_threadCreationMutex; |
- RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; |
- |
- OwnPtr<WeakPtrFactory<WorkerThread> > m_weakFactory; |
// Used to signal thread shutdown. |
OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; |