Index: Source/core/workers/WorkerThread.h |
diff --git a/Source/core/workers/WorkerThread.h b/Source/core/workers/WorkerThread.h |
index deb0028e77ccda3d21b431cfbdad5558145386a4..2dccd35e0ef97c02496a1b0fbd1cd4b56e8d8264 100644 |
--- a/Source/core/workers/WorkerThread.h |
+++ b/Source/core/workers/WorkerThread.h |
@@ -27,10 +27,14 @@ |
#ifndef WorkerThread_h |
#define WorkerThread_h |
+#include "core/dom/ExecutionContextTask.h" |
#include "core/frame/csp/ContentSecurityPolicy.h" |
-#include "core/workers/WorkerRunLoop.h" |
+#include "core/workers/WorkerGlobalScope.h" |
+#include "platform/SharedTimer.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" |
@@ -43,40 +47,50 @@ namespace blink { |
class KURL; |
class WorkerGlobalScope; |
+ class WorkerInspectorController; |
class WorkerLoaderProxy; |
class WorkerReportingProxy; |
+ class WorkerSharedTimer; |
+ class WorkerThreadShutdownFinishTask; |
class WorkerThreadStartupData; |
- class WorkerInspectorController; |
+ class WorkerThreadTask; |
enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerGlobalScopeOnStart }; |
+ |
class WorkerThread : public RefCounted<WorkerThread> { |
public: |
virtual ~WorkerThread(); |
- bool start(); |
- void stop(); |
+ virtual void start(); |
+ virtual 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>); |
- MessageQueueWaitResult runDebuggerTask(WorkerRunLoop::WaitMode = WorkerRunLoop::WaitForMessage); |
- bool terminated() { return m_runLoop.terminated(); } |
+ 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; } |
// Number of active worker threads. |
static unsigned workerThreadCount(); |
- WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(); } |
- |
void interruptAndDispatchInspectorCommands(); |
void setWorkerInspectorController(WorkerInspectorController*); |
@@ -86,28 +100,32 @@ namespace blink { |
// Factory method for creating a new worker context for the thread. |
virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
- // Executes the event loop for the worker thread. Derived classes can override to perform actions before/after entering the event loop. |
- virtual void runEventLoop(); |
+ virtual void postInitialize() { } |
private: |
- // Static function executed as the core routine on the new thread. Passed a pointer to a WorkerThread object. |
- static void workerThreadStart(void*); |
+ friend class WorkerThreadShutdownFinishTask; |
+ |
+ 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; |
}; |