OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 28 matching lines...) Expand all Loading... |
39 class WebWaitableEvent; | 39 class WebWaitableEvent; |
40 } | 40 } |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class KURL; | 44 class KURL; |
45 class WorkerGlobalScope; | 45 class WorkerGlobalScope; |
46 class WorkerLoaderProxy; | 46 class WorkerLoaderProxy; |
47 class WorkerReportingProxy; | 47 class WorkerReportingProxy; |
48 class WorkerThreadStartupData; | 48 class WorkerThreadStartupData; |
| 49 class WorkerInspectorController; |
49 | 50 |
50 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG
lobalScopeOnStart }; | 51 enum WorkerThreadStartMode { DontPauseWorkerGlobalScopeOnStart, PauseWorkerG
lobalScopeOnStart }; |
51 | 52 |
52 class WorkerThread : public RefCounted<WorkerThread> { | 53 class WorkerThread : public RefCounted<WorkerThread> { |
53 public: | 54 public: |
54 virtual ~WorkerThread(); | 55 virtual ~WorkerThread(); |
55 | 56 |
56 bool start(); | 57 bool start(); |
57 void stop(); | 58 void stop(); |
58 | 59 |
59 // Can be used to wait for this worker thread to shut down. | 60 // Can be used to wait for this worker thread to shut down. |
60 // (This is signalled on the main thread, so it's assumed to be waited o
n the worker context thread) | 61 // (This is signalled on the main thread, so it's assumed to be waited o
n the worker context thread) |
61 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get();
} | 62 blink::WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get();
} |
62 | 63 |
63 bool isCurrentThread() const; | 64 bool isCurrentThread() const; |
64 WorkerRunLoop& runLoop() { return m_runLoop; } | 65 WorkerRunLoop& runLoop() { return m_runLoop; } |
65 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx
y; } | 66 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProx
y; } |
66 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo
rtingProxy; } | 67 WorkerReportingProxy& workerReportingProxy() const { return m_workerRepo
rtingProxy; } |
67 | 68 |
68 void postTask(PassOwnPtr<ExecutionContextTask>); | 69 void postTask(PassOwnPtr<ExecutionContextTask>); |
69 void postDebuggerTask(PassOwnPtr<ExecutionContextTask>); | 70 void postDebuggerTask(PassOwnPtr<ExecutionContextTask>); |
70 | 71 |
71 MessageQueueWaitResult runDebuggerTask(WorkerRunLoop::WaitMode = WorkerR
unLoop::WaitForMessage); | 72 MessageQueueWaitResult runDebuggerTask(WorkerRunLoop::WaitMode = WorkerR
unLoop::WaitForMessage); |
72 bool terminated() { return m_runLoop.terminated(); } | 73 bool terminated() { return m_runLoop.terminated(); } |
73 | 74 |
74 // Number of active worker threads. | 75 // Number of active worker threads. |
75 static unsigned workerThreadCount(); | 76 static unsigned workerThreadCount(); |
76 | 77 |
| 78 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(
); } |
| 79 |
| 80 void interruptAndDispatchInspectorCommands(); |
| 81 void setWorkerInspectorController(WorkerInspectorController*); |
| 82 |
77 protected: | 83 protected: |
78 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBe
RawPtr<WorkerThreadStartupData>); | 84 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBe
RawPtr<WorkerThreadStartupData>); |
79 | 85 |
80 // Factory method for creating a new worker context for the thread. | 86 // Factory method for creating a new worker context for the thread. |
81 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScop
e(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; | 87 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScop
e(PassOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
82 | 88 |
83 // Executes the event loop for the worker thread. Derived classes can ov
erride to perform actions before/after entering the event loop. | 89 // Executes the event loop for the worker thread. Derived classes can ov
erride to perform actions before/after entering the event loop. |
84 virtual void runEventLoop(); | 90 virtual void runEventLoop(); |
85 | 91 |
86 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope.get(
); } | |
87 | |
88 private: | 92 private: |
89 // Static function executed as the core routine on the new thread. Passe
d a pointer to a WorkerThread object. | 93 // Static function executed as the core routine on the new thread. Passe
d a pointer to a WorkerThread object. |
90 static void workerThreadStart(void*); | 94 static void workerThreadStart(void*); |
91 | 95 |
92 void workerThread(); | 96 void workerThread(); |
93 | 97 |
94 ThreadIdentifier m_threadID; | 98 ThreadIdentifier m_threadID; |
95 WorkerRunLoop m_runLoop; | 99 WorkerRunLoop m_runLoop; |
96 WorkerLoaderProxy& m_workerLoaderProxy; | 100 WorkerLoaderProxy& m_workerLoaderProxy; |
97 WorkerReportingProxy& m_workerReportingProxy; | 101 WorkerReportingProxy& m_workerReportingProxy; |
98 | 102 |
99 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 103 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
100 Mutex m_threadCreationMutex; | 104 Mutex m_threadCreationMutex; |
101 | 105 |
| 106 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorContr
oller; |
| 107 Mutex m_workerInspectorControllerMutex; |
| 108 |
102 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; | 109 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; |
103 | 110 |
104 // Used to signal thread shutdown. | 111 // Used to signal thread shutdown. |
105 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; | 112 OwnPtr<blink::WebWaitableEvent> m_shutdownEvent; |
106 }; | 113 }; |
107 | 114 |
108 } // namespace blink | 115 } // namespace blink |
109 | 116 |
110 #endif // WorkerThread_h | 117 #endif // WorkerThread_h |
OLD | NEW |