Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 enum WorkerThreadStartMode { | 53 enum WorkerThreadStartMode { |
| 54 DontPauseWorkerGlobalScopeOnStart, | 54 DontPauseWorkerGlobalScopeOnStart, |
| 55 PauseWorkerGlobalScopeOnStart | 55 PauseWorkerGlobalScopeOnStart |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // TODO(sadrul): Rename to WorkerScript. | 58 // TODO(sadrul): Rename to WorkerScript. |
| 59 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { | 59 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { |
| 60 public: | 60 public: |
| 61 virtual ~WorkerThread(); | 61 virtual ~WorkerThread(); |
| 62 | 62 |
| 63 // Called on the main thread. | |
|
Noel Gordon
2015/06/11 07:07:03
Is this true, or is this an implicit statement of
kinuko
2015/06/11 08:59:44
It just states how our system works today. Current
| |
| 63 virtual void start(PassOwnPtr<WorkerThreadStartupData>); | 64 virtual void start(PassOwnPtr<WorkerThreadStartupData>); |
| 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(); |
| 74 | 75 |
| 75 v8::Isolate* isolate() const { return m_isolate; } | 76 v8::Isolate* isolate() const { return m_isolate; } |
| 76 | 77 |
| 77 // 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. |
| 78 // (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) |
| 79 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 80 | 81 |
| 81 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
| 83 | |
| 84 // Called in shutdown sequence. Internally calls stop() (or stopInternal) | |
| 85 // and wait (by *blocking* the calling thread) until the worker(s) is/are | |
| 86 // shut down. | |
| 82 void terminateAndWait(); | 87 void terminateAndWait(); |
| 83 static void terminateAndWaitForAllWorkers(); | 88 static void terminateAndWaitForAllWorkers(); |
| 84 | 89 |
| 85 bool isCurrentThread(); | 90 bool isCurrentThread(); |
| 86 WorkerLoaderProxy* workerLoaderProxy() const | 91 WorkerLoaderProxy* workerLoaderProxy() const |
| 87 { | 92 { |
| 88 RELEASE_ASSERT(m_workerLoaderProxy); | 93 RELEASE_ASSERT(m_workerLoaderProxy); |
| 89 return m_workerLoaderProxy.get(); | 94 return m_workerLoaderProxy.get(); |
| 90 } | 95 } |
| 91 | 96 |
| 92 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; } | 97 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; } |
| 93 | 98 |
| 94 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); | 99 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); |
| 95 void appendDebuggerTask(PassOwnPtr<WebThread::Task>); | 100 void appendDebuggerTask(PassOwnPtr<WebThread::Task>); |
| 96 | 101 |
| 97 enum WaitMode { WaitForMessage, DontWaitForMessage }; | 102 enum WaitMode { WaitForMessage, DontWaitForMessage }; |
| 98 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); | 103 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); |
| 99 | 104 |
| 100 // These methods should be called if the holder of the thread is | 105 // These methods should be called if the holder of the thread is |
| 101 // going to call runDebuggerTask in a loop. | 106 // going to call runDebuggerTask in a loop. |
| 102 void willEnterNestedLoop(); | 107 void willEnterNestedLoop(); |
| 103 void didLeaveNestedLoop(); | 108 void didLeaveNestedLoop(); |
| 104 | 109 |
| 105 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge t(); } | 110 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge t(); } |
| 111 | |
| 112 // Returns true once stop() (or one of the terminate* methods which | |
| 113 // internally calls stop) is called. | |
| 106 bool terminated(); | 114 bool terminated(); |
| 107 | 115 |
| 108 // Number of active worker threads. | 116 // Number of active worker threads. |
| 109 static unsigned workerThreadCount(); | 117 static unsigned workerThreadCount(); |
| 110 | 118 |
| 111 PlatformThreadId platformThreadId(); | 119 PlatformThreadId platformThreadId(); |
| 112 | 120 |
| 113 void interruptAndDispatchInspectorCommands(); | 121 void interruptAndDispatchInspectorCommands(); |
| 114 void setWorkerInspectorController(WorkerInspectorController*); | 122 void setWorkerInspectorController(WorkerInspectorController*); |
| 115 | 123 |
| 116 protected: | 124 protected: |
| 117 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 125 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
| 118 | 126 |
| 119 // Factory method for creating a new worker context for the thread. | 127 // Factory method for creating a new worker context for the thread. |
| 120 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; | 128 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; |
| 121 | 129 |
| 122 virtual void postInitialize() { } | 130 virtual void postInitialize() { } |
| 123 | 131 |
| 124 virtual v8::Isolate* initializeIsolate(); | 132 virtual v8::Isolate* initializeIsolate(); |
| 125 virtual void willDestroyIsolate(); | 133 virtual void willDestroyIsolate(); |
| 126 virtual void destroyIsolate(); | 134 virtual void destroyIsolate(); |
| 127 virtual void terminateV8Execution(); | 135 virtual void terminateV8Execution(); |
| 128 | 136 |
| 129 // This is protected virtual for testing. | 137 // This is protected virtual for testing. |
| 130 virtual bool doIdleGc(double deadlineSeconds); | 138 virtual bool doIdleGc(double deadlineSeconds); |
| 131 | 139 |
| 132 private: | 140 private: |
| 133 friend class WorkerMicrotaskRunner; | 141 friend class WorkerMicrotaskRunner; |
| 134 | 142 |
| 135 void stopInShutdownSequence(); | 143 // Called on the main thread. |
| 136 void stopInternal(); | 144 void stopInternal(); |
| 137 | 145 |
| 146 // Called on the worker thread. | |
| 138 void initialize(PassOwnPtr<WorkerThreadStartupData>); | 147 void initialize(PassOwnPtr<WorkerThreadStartupData>); |
| 139 void shutdown(); | 148 void shutdown(); |
| 140 void performIdleWork(double deadlineSeconds); | 149 void performIdleWork(double deadlineSeconds); |
| 141 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); | 150 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); |
| 142 | 151 |
| 143 bool m_started; | 152 bool m_started; |
| 144 bool m_terminated; | 153 bool m_terminated; |
| 145 bool m_shutdown; | 154 bool m_shutdown; |
| 146 MessageQueue<WebThread::Task> m_debuggerMessageQueue; | 155 MessageQueue<WebThread::Task> m_debuggerMessageQueue; |
| 147 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 156 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 // Used to signal thread shutdown. | 173 // Used to signal thread shutdown. |
| 165 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 174 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
| 166 | 175 |
| 167 // Used to signal thread termination. | 176 // Used to signal thread termination. |
| 168 OwnPtr<WebWaitableEvent> m_terminationEvent; | 177 OwnPtr<WebWaitableEvent> m_terminationEvent; |
| 169 }; | 178 }; |
| 170 | 179 |
| 171 } // namespace blink | 180 } // namespace blink |
| 172 | 181 |
| 173 #endif // WorkerThread_h | 182 #endif // WorkerThread_h |
| OLD | NEW |