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 17 matching lines...) Expand all Loading... | |
62 virtual ~WorkerThread(); | 63 virtual ~WorkerThread(); |
63 | 64 |
64 virtual void start(PassOwnPtr<WorkerThreadStartupData>); | 65 virtual void start(PassOwnPtr<WorkerThreadStartupData>); |
65 virtual void stop(); | 66 virtual void stop(); |
66 | 67 |
67 // Returns the thread this worker runs on. Some implementations can create | 68 // Returns the thread this worker runs on. Some implementations can create |
68 // a new thread on the first call (e.g. shared, dedicated workers), whereas | 69 // a new thread on the first call (e.g. shared, dedicated workers), whereas |
69 // some implementations can use an existing thread that is already being | 70 // some implementations can use an existing thread that is already being |
70 // used by other workers (e.g. compositor workers). | 71 // used by other workers (e.g. compositor workers). |
71 virtual WebThreadSupportingGC& backingThread() = 0; | 72 virtual WebThreadSupportingGC& backingThread() = 0; |
72 | |
73 virtual void didStartRunLoop(); | |
74 virtual void didStopRunLoop(); | 73 virtual void didStopRunLoop(); |
75 | 74 |
76 v8::Isolate* isolate() const { return m_isolate; } | 75 v8::Isolate* isolate(); |
77 | 76 |
78 // Can be used to wait for this worker thread to shut down. | 77 // Can be used to wait for this worker thread to shut down. |
79 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread) | 78 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread) |
80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 79 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
81 | 80 |
82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 81 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
83 void terminateAndWait(); | 82 void terminateAndWait(); |
84 static void terminateAndWaitForAllWorkers(); | 83 static void terminateAndWaitForAllWorkers(); |
85 | 84 |
86 bool isCurrentThread(); | 85 bool isCurrentThread(); |
(...skipping 28 matching lines...) Expand all Loading... | |
115 void setWorkerInspectorController(WorkerInspectorController*); | 114 void setWorkerInspectorController(WorkerInspectorController*); |
116 | 115 |
117 protected: | 116 protected: |
118 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 117 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
119 | 118 |
120 // Factory method for creating a new worker context for the thread. | 119 // Factory method for creating a new worker context for the thread. |
121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; | 120 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; |
122 | 121 |
123 virtual void postInitialize() { } | 122 virtual void postInitialize() { } |
124 | 123 |
125 virtual v8::Isolate* initializeIsolate(); | 124 virtual OwnPtr<WorkerV8Isolate>& workerIsolate() = 0; |
kinuko
2015/05/29 17:45:18
Returning OwnPtr but not for the caller to take ow
sadrul
2015/05/29 18:26:32
With this change:
. For managing the WebThread: W
| |
126 virtual void willDestroyIsolate(); | |
127 virtual void destroyIsolate(); | |
128 virtual void terminateV8Execution(); | 125 virtual void terminateV8Execution(); |
129 | 126 |
127 virtual void didStartRunLoop(); | |
kinuko
2015/05/29 17:45:18
nit: I think this can be public as far as didStart
sadrul
2015/05/29 18:26:32
Acknowledged. Will make this change.
sadrul
2015/06/01 05:24:11
Done.
| |
128 virtual void initializeBackingThread(); | |
129 virtual void shutdownBackingThread(); | |
130 | |
130 // This is protected virtual for testing. | 131 // This is protected virtual for testing. |
131 virtual bool doIdleGc(double deadlineSeconds); | 132 virtual bool doIdleGc(double deadlineSeconds); |
132 | 133 |
133 private: | 134 private: |
134 friend class WorkerSharedTimer; | 135 friend class WorkerSharedTimer; |
135 friend class WorkerMicrotaskRunner; | 136 friend class WorkerMicrotaskRunner; |
136 | 137 |
137 void stopInShutdownSequence(); | 138 void stopInShutdownSequence(); |
138 void stopInternal(); | 139 void stopInternal(); |
139 | 140 |
140 void initialize(PassOwnPtr<WorkerThreadStartupData>); | 141 void initialize(PassOwnPtr<WorkerThreadStartupData>); |
141 void shutdown(); | 142 void shutdown(); |
142 void performIdleWork(double deadlineSeconds); | 143 void performIdleWork(double deadlineSeconds); |
143 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); | 144 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); |
144 | 145 |
145 bool m_started; | 146 bool m_started; |
146 bool m_terminated; | 147 bool m_terminated; |
147 bool m_shutdown; | 148 bool m_shutdown; |
148 MessageQueue<WebThread::Task> m_debuggerMessageQueue; | 149 MessageQueue<WebThread::Task> m_debuggerMessageQueue; |
149 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 150 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
150 | 151 |
151 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 152 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
152 WorkerReportingProxy& m_workerReportingProxy; | 153 WorkerReportingProxy& m_workerReportingProxy; |
153 RawPtr<WebScheduler> m_webScheduler; // Not owned. | 154 RawPtr<WebScheduler> m_webScheduler; // Not owned. |
154 | 155 |
155 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; | 156 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; |
156 Mutex m_workerInspectorControllerMutex; | 157 Mutex m_workerInspectorControllerMutex; |
157 | 158 |
158 // This lock protects |m_workerGlobalScope|, |m_terminated|, |m_isolate| and |m_microtaskRunner|. | 159 // This lock protects |m_workerGlobalScope|, and |m_terminated|. |
159 Mutex m_threadStateMutex; | 160 Mutex m_threadStateMutex; |
160 | 161 |
161 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 162 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
162 | 163 |
163 v8::Isolate* m_isolate; | |
164 OwnPtr<V8IsolateInterruptor> m_interruptor; | |
165 | |
166 // Used to signal thread shutdown. | 164 // Used to signal thread shutdown. |
167 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 165 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
168 | 166 |
169 // Used to signal thread termination. | 167 // Used to signal thread termination. |
170 OwnPtr<WebWaitableEvent> m_terminationEvent; | 168 OwnPtr<WebWaitableEvent> m_terminationEvent; |
171 }; | 169 }; |
172 | 170 |
173 } // namespace blink | 171 } // namespace blink |
174 | 172 |
175 #endif // WorkerThread_h | 173 #endif // WorkerThread_h |
OLD | NEW |