| 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 13 matching lines...) Expand all Loading... |
| 24 * | 24 * |
| 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/WorkerIsolateWrapper.h" |
| 34 #include "core/workers/WorkerLoaderProxy.h" | 35 #include "core/workers/WorkerLoaderProxy.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 |
| (...skipping 18 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(); | 73 virtual void didStartRunLoop(); |
| 74 virtual void didStopRunLoop(); | 74 virtual void didStopRunLoop(); |
| 75 | 75 |
| 76 v8::Isolate* isolate() const { return m_isolate; } | 76 v8::Isolate* isolate(); |
| 77 | 77 |
| 78 // Can be used to wait for this worker thread to shut down. | 78 // 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) | 79 // (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(); } | 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 81 | 81 |
| 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
| 83 void terminateAndWait(); | 83 void terminateAndWait(); |
| 84 static void terminateAndWaitForAllWorkers(); | 84 static void terminateAndWaitForAllWorkers(); |
| 85 | 85 |
| 86 bool isCurrentThread(); | 86 bool isCurrentThread(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 115 void setWorkerInspectorController(WorkerInspectorController*); | 115 void setWorkerInspectorController(WorkerInspectorController*); |
| 116 | 116 |
| 117 protected: | 117 protected: |
| 118 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 118 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
| 119 | 119 |
| 120 // Factory method for creating a new worker context for the thread. | 120 // Factory method for creating a new worker context for the thread. |
| 121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; | 121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; |
| 122 | 122 |
| 123 virtual void postInitialize() { } | 123 virtual void postInitialize() { } |
| 124 | 124 |
| 125 virtual v8::Isolate* initializeIsolate(); | 125 // Both of these methods are called in the worker thread. |
| 126 virtual void willDestroyIsolate(); | 126 virtual void initializeBackingThread(); |
| 127 virtual void destroyIsolate(); | 127 virtual void shutdownBackingThread(); |
| 128 |
| 129 // The WorkerIsolateWrapper is created in the worker thread. |
| 130 virtual PassOwnPtr<WorkerIsolateWrapper> createIsolateWrapper(); |
| 131 |
| 132 // This is called on the main-thread. |
| 128 virtual void terminateV8Execution(); | 133 virtual void terminateV8Execution(); |
| 129 | 134 |
| 130 // This is protected virtual for testing. | 135 // This is protected virtual for testing. |
| 131 virtual bool doIdleGc(double deadlineSeconds); | 136 virtual bool doIdleGc(double deadlineSeconds); |
| 132 | 137 |
| 133 private: | 138 private: |
| 134 friend class WorkerSharedTimer; | 139 friend class WorkerSharedTimer; |
| 135 friend class WorkerMicrotaskRunner; | 140 friend class WorkerMicrotaskRunner; |
| 136 | 141 |
| 137 void stopInShutdownSequence(); | 142 void stopInShutdownSequence(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 MessageQueue<WebThread::Task> m_debuggerMessageQueue; | 153 MessageQueue<WebThread::Task> m_debuggerMessageQueue; |
| 149 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 154 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
| 150 | 155 |
| 151 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 156 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
| 152 WorkerReportingProxy& m_workerReportingProxy; | 157 WorkerReportingProxy& m_workerReportingProxy; |
| 153 RawPtr<WebScheduler> m_webScheduler; // Not owned. | 158 RawPtr<WebScheduler> m_webScheduler; // Not owned. |
| 154 | 159 |
| 155 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; | 160 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; |
| 156 Mutex m_workerInspectorControllerMutex; | 161 Mutex m_workerInspectorControllerMutex; |
| 157 | 162 |
| 158 // This lock protects |m_workerGlobalScope|, |m_terminated|, |m_isolate| and
|m_microtaskRunner|. | 163 // This lock protects |m_workerGlobalScope|, |m_terminated|, and |m_isolateW
rapper|. |
| 159 Mutex m_threadStateMutex; | 164 Mutex m_threadStateMutex; |
| 160 | 165 |
| 161 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 166 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
| 162 | 167 OwnPtr<WorkerIsolateWrapper> m_isolateWrapper; |
| 163 v8::Isolate* m_isolate; | |
| 164 OwnPtr<V8IsolateInterruptor> m_interruptor; | |
| 165 | 168 |
| 166 // Used to signal thread shutdown. | 169 // Used to signal thread shutdown. |
| 167 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 170 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
| 168 | 171 |
| 169 // Used to signal thread termination. | 172 // Used to signal thread termination. |
| 170 OwnPtr<WebWaitableEvent> m_terminationEvent; | 173 OwnPtr<WebWaitableEvent> m_terminationEvent; |
| 171 }; | 174 }; |
| 172 | 175 |
| 173 } // namespace blink | 176 } // namespace blink |
| 174 | 177 |
| 175 #endif // WorkerThread_h | 178 #endif // WorkerThread_h |
| OLD | NEW |