| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | 63 // Called on the main thread. |
| 64 virtual void start(PassOwnPtr<WorkerThreadStartupData>); | 64 void start(PassOwnPtr<WorkerThreadStartupData>); |
| 65 virtual void stop(); | 65 void terminate(); |
| 66 | 66 |
| 67 // Returns the thread this worker runs on. Some implementations can create | 67 // 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 | 68 // 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 | 69 // some implementations can use an existing thread that is already being |
| 70 // used by other workers (e.g. compositor workers). | 70 // used by other workers (e.g. compositor workers). |
| 71 virtual WebThreadSupportingGC& backingThread() = 0; | 71 virtual WebThreadSupportingGC& backingThread() = 0; |
| 72 | 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() const { return m_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 signaled on the main thread, so it's assumed to be waited on |
| 80 // the worker context thread) |
| 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 81 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 81 | 82 |
| 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 83 // Called in shutdown sequence. Internally calls terminate() (or |
| 83 | 84 // terminateInternal) and wait (by *blocking* the calling thread) until the |
| 84 // Called in shutdown sequence. Internally calls stop() (or stopInternal) | 85 // worker(s) is/are shut down. |
| 85 // and wait (by *blocking* the calling thread) until the worker(s) is/are | |
| 86 // shut down. | |
| 87 void terminateAndWait(); | 86 void terminateAndWait(); |
| 88 static void terminateAndWaitForAllWorkers(); | 87 static void terminateAndWaitForAllWorkers(); |
| 89 | 88 |
| 90 bool isCurrentThread(); | 89 bool isCurrentThread(); |
| 91 WorkerLoaderProxy* workerLoaderProxy() const | 90 WorkerLoaderProxy* workerLoaderProxy() const |
| 92 { | 91 { |
| 93 RELEASE_ASSERT(m_workerLoaderProxy); | 92 RELEASE_ASSERT(m_workerLoaderProxy); |
| 94 return m_workerLoaderProxy.get(); | 93 return m_workerLoaderProxy.get(); |
| 95 } | 94 } |
| 96 | 95 |
| 97 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin
gProxy; } | 96 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin
gProxy; } |
| 98 | 97 |
| 99 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); | 98 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); |
| 100 void appendDebuggerTask(PassOwnPtr<WebThread::Task>); | 99 void appendDebuggerTask(PassOwnPtr<WebThread::Task>); |
| 101 | 100 |
| 102 enum WaitMode { WaitForMessage, DontWaitForMessage }; | 101 enum WaitMode { WaitForMessage, DontWaitForMessage }; |
| 103 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); | 102 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); |
| 104 | 103 |
| 105 // These methods should be called if the holder of the thread is | 104 // These methods should be called if the holder of the thread is |
| 106 // going to call runDebuggerTask in a loop. | 105 // going to call runDebuggerTask in a loop. |
| 107 void willEnterNestedLoop(); | 106 void willEnterNestedLoop(); |
| 108 void didLeaveNestedLoop(); | 107 void didLeaveNestedLoop(); |
| 109 | 108 |
| 110 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } | 109 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } |
| 111 | 110 |
| 112 // Returns true once stop() (or one of the terminate* methods which | 111 // Returns true once one of the terminate* methods is called. |
| 113 // internally calls stop) is called. | |
| 114 bool terminated(); | 112 bool terminated(); |
| 115 | 113 |
| 116 // Number of active worker threads. | 114 // Number of active worker threads. |
| 117 static unsigned workerThreadCount(); | 115 static unsigned workerThreadCount(); |
| 118 | 116 |
| 119 PlatformThreadId platformThreadId(); | 117 PlatformThreadId platformThreadId(); |
| 120 | 118 |
| 121 void interruptAndDispatchInspectorCommands(); | 119 void interruptAndDispatchInspectorCommands(); |
| 122 void setWorkerInspectorController(WorkerInspectorController*); | 120 void setWorkerInspectorController(WorkerInspectorController*); |
| 123 | 121 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 virtual void destroyIsolate(); | 132 virtual void destroyIsolate(); |
| 135 virtual void terminateV8Execution(); | 133 virtual void terminateV8Execution(); |
| 136 | 134 |
| 137 // This is protected virtual for testing. | 135 // This is protected virtual for testing. |
| 138 virtual bool doIdleGc(double deadlineSeconds); | 136 virtual bool doIdleGc(double deadlineSeconds); |
| 139 | 137 |
| 140 private: | 138 private: |
| 141 friend class WorkerMicrotaskRunner; | 139 friend class WorkerMicrotaskRunner; |
| 142 | 140 |
| 143 // Called on the main thread. | 141 // Called on the main thread. |
| 144 void stopInternal(); | 142 void terminateInternal(); |
| 145 | 143 |
| 146 // Called on the worker thread. | 144 // Called on the worker thread. |
| 147 void initialize(PassOwnPtr<WorkerThreadStartupData>); | 145 void initialize(PassOwnPtr<WorkerThreadStartupData>); |
| 148 void shutdown(); | 146 void shutdown(); |
| 149 void performIdleWork(double deadlineSeconds); | 147 void performIdleWork(double deadlineSeconds); |
| 150 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas
k>, long long delayMs); | 148 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas
k>, long long delayMs); |
| 151 | 149 |
| 152 bool m_started; | 150 bool m_started; |
| 153 bool m_terminated; | 151 bool m_terminated; |
| 154 bool m_shutdown; | 152 bool m_shutdown; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 173 // Used to signal thread shutdown. | 171 // Used to signal thread shutdown. |
| 174 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 172 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
| 175 | 173 |
| 176 // Used to signal thread termination. | 174 // Used to signal thread termination. |
| 177 OwnPtr<WebWaitableEvent> m_terminationEvent; | 175 OwnPtr<WebWaitableEvent> m_terminationEvent; |
| 178 }; | 176 }; |
| 179 | 177 |
| 180 } // namespace blink | 178 } // namespace blink |
| 181 | 179 |
| 182 #endif // WorkerThread_h | 180 #endif // WorkerThread_h |
| OLD | NEW |