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 14 matching lines...) Expand all Loading... |
25 */ | 25 */ |
26 | 26 |
27 #ifndef WorkerThread_h | 27 #ifndef WorkerThread_h |
28 #define WorkerThread_h | 28 #define WorkerThread_h |
29 | 29 |
30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
31 #include "core/dom/ExecutionContextTask.h" | 31 #include "core/dom/ExecutionContextTask.h" |
32 #include "core/frame/csp/ContentSecurityPolicy.h" | 32 #include "core/frame/csp/ContentSecurityPolicy.h" |
33 #include "core/workers/WorkerGlobalScope.h" | 33 #include "core/workers/WorkerGlobalScope.h" |
34 #include "core/workers/WorkerLoaderProxy.h" | 34 #include "core/workers/WorkerLoaderProxy.h" |
| 35 #include "core/workers/WorkerV8Isolate.h" |
35 #include "platform/WebThreadSupportingGC.h" | 36 #include "platform/WebThreadSupportingGC.h" |
36 #include "platform/weborigin/SecurityOrigin.h" | 37 #include "platform/weborigin/SecurityOrigin.h" |
37 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
38 #include "wtf/MessageQueue.h" | 39 #include "wtf/MessageQueue.h" |
39 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
40 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
42 #include <v8.h> | 43 #include <v8.h> |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
(...skipping 19 matching lines...) Expand all Loading... |
64 virtual void stop(); | 65 virtual void stop(); |
65 | 66 |
66 // Returns the thread this worker runs on. Some implementations can create | 67 // Returns the thread this worker runs on. Some implementations can create |
67 // a new thread on the first call (e.g. shared, dedicated workers), whereas | 68 // a new thread on the first call (e.g. shared, dedicated workers), whereas |
68 // some implementations can use an existing thread that is already being | 69 // some implementations can use an existing thread that is already being |
69 // used by other workers (e.g. compositor workers). | 70 // used by other workers (e.g. compositor workers). |
70 virtual WebThreadSupportingGC& backingThread() = 0; | 71 virtual WebThreadSupportingGC& backingThread() = 0; |
71 | 72 |
72 virtual void didStartRunLoop(); | 73 virtual void didStartRunLoop(); |
73 virtual void didStopRunLoop(); | 74 virtual void didStopRunLoop(); |
| 75 virtual void initializeBackingThread(); |
| 76 virtual void shutdownBackingThread(); |
74 | 77 |
75 v8::Isolate* isolate() const { return m_isolate; } | 78 v8::Isolate* isolate() const { return m_isolate ? m_isolate->isolate() : nul
lptr; } |
76 | 79 |
77 // Can be used to wait for this worker thread to shut down. | 80 // Can be used to wait for this worker thread to shut down. |
78 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) | 81 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) |
79 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 82 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
80 | 83 |
81 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 84 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
82 void terminateAndWait(); | 85 void terminateAndWait(); |
83 static void terminateAndWaitForAllWorkers(); | 86 static void terminateAndWaitForAllWorkers(); |
84 | 87 |
85 bool isCurrentThread(); | 88 bool isCurrentThread(); |
(...skipping 28 matching lines...) Expand all Loading... |
114 void setWorkerInspectorController(WorkerInspectorController*); | 117 void setWorkerInspectorController(WorkerInspectorController*); |
115 | 118 |
116 protected: | 119 protected: |
117 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 120 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
118 | 121 |
119 // Factory method for creating a new worker context for the thread. | 122 // Factory method for creating a new worker context for the thread. |
120 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; | 123 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; |
121 | 124 |
122 virtual void postInitialize() { } | 125 virtual void postInitialize() { } |
123 | 126 |
124 virtual v8::Isolate* initializeIsolate(); | 127 virtual PassOwnPtr<WorkerV8Isolate> initializeIsolate(); |
125 virtual void willDestroyIsolate(); | 128 virtual void willDestroyIsolate(); |
126 virtual void destroyIsolate(); | 129 virtual void destroyIsolate(); |
127 virtual void terminateV8Execution(); | 130 virtual void terminateV8Execution(); |
128 | 131 |
129 // This is protected virtual for testing. | 132 // This is protected virtual for testing. |
130 virtual bool doIdleGc(double deadlineSeconds); | 133 virtual bool doIdleGc(double deadlineSeconds); |
131 | 134 |
132 private: | 135 private: |
133 friend class WorkerMicrotaskRunner; | 136 friend class WorkerMicrotaskRunner; |
134 | 137 |
(...skipping 11 matching lines...) Expand all Loading... |
146 MessageQueue<WebThread::Task> m_debuggerMessageQueue; | 149 MessageQueue<WebThread::Task> m_debuggerMessageQueue; |
147 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 150 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
148 | 151 |
149 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 152 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
150 WorkerReportingProxy& m_workerReportingProxy; | 153 WorkerReportingProxy& m_workerReportingProxy; |
151 RawPtr<WebScheduler> m_webScheduler; // Not owned. | 154 RawPtr<WebScheduler> m_webScheduler; // Not owned. |
152 | 155 |
153 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; | 156 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; |
154 Mutex m_workerInspectorControllerMutex; | 157 Mutex m_workerInspectorControllerMutex; |
155 | 158 |
156 // This lock protects |m_workerGlobalScope|, |m_terminated|, |m_isolate| and
|m_microtaskRunner|. | 159 // This lock protects |m_workerGlobalScope|, |m_terminated|, and |m_isolate|
. |
157 Mutex m_threadStateMutex; | 160 Mutex m_threadStateMutex; |
158 | 161 |
159 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 162 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
160 | 163 |
161 v8::Isolate* m_isolate; | 164 OwnPtr<WorkerV8Isolate> m_isolate; |
162 OwnPtr<V8IsolateInterruptor> m_interruptor; | |
163 | 165 |
164 // Used to signal thread shutdown. | 166 // Used to signal thread shutdown. |
165 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 167 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
166 | 168 |
167 // Used to signal thread termination. | 169 // Used to signal thread termination. |
168 OwnPtr<WebWaitableEvent> m_terminationEvent; | 170 OwnPtr<WebWaitableEvent> m_terminationEvent; |
169 }; | 171 }; |
170 | 172 |
171 } // namespace blink | 173 } // namespace blink |
172 | 174 |
173 #endif // WorkerThread_h | 175 #endif // WorkerThread_h |
OLD | NEW |