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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 class WorkerThreadShutdownFinishTask; | 51 class WorkerThreadShutdownFinishTask; |
52 class WorkerThreadStartupData; | 52 class WorkerThreadStartupData; |
53 class WorkerThreadTask; | 53 class WorkerThreadTask; |
54 | 54 |
55 enum WorkerThreadStartMode { | 55 enum WorkerThreadStartMode { |
56 DontPauseWorkerGlobalScopeOnStart, | 56 DontPauseWorkerGlobalScopeOnStart, |
57 PauseWorkerGlobalScopeOnStart | 57 PauseWorkerGlobalScopeOnStart |
58 }; | 58 }; |
59 | 59 |
60 class WorkerThread : public RefCounted<WorkerThread> { | 60 class WorkerThread : public RefCounted<WorkerThread> { |
| 61 |
| 62 class WorkerThreadTask : public blink::WebThread::Task { |
| 63 WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED; |
| 64 public: |
| 65 static PassOwnPtr<WorkerThreadTask> create(WorkerThread& |
| 66 , PassOwnPtr<ExecutionContextTask>, bool); |
| 67 |
| 68 virtual ~WorkerThreadTask() { } |
| 69 virtual void run() override; |
| 70 |
| 71 void setIsIdleHandlerTask(bool isIdleHandlerTask) { m_isIdleHandlerTask
= isIdleHandlerTask; } |
| 72 bool isIdleHandlerTask() const { return m_isIdleHandlerTask; } |
| 73 void cancelTask() { m_isTaskCanceled = true; }; |
| 74 double creationTimeStamp() const { return m_timeStamp; } |
| 75 |
| 76 private: |
| 77 WorkerThreadTask(WorkerThread&, PassOwnPtr<ExecutionContextTask>, bool); |
| 78 |
| 79 WorkerThread& m_workerThread; |
| 80 OwnPtr<ExecutionContextTask> m_task; |
| 81 bool m_isInstrumented; |
| 82 bool m_isIdleHandlerTask; |
| 83 bool m_isTaskCanceled; |
| 84 // Creation time stamp |
| 85 double m_timeStamp; |
| 86 }; |
| 87 |
61 public: | 88 public: |
62 virtual ~WorkerThread(); | 89 virtual ~WorkerThread(); |
63 | 90 |
64 virtual void start(); | 91 virtual void start(); |
65 virtual void stop(); | 92 virtual void stop(); |
66 | 93 |
67 // Can be used to wait for this worker thread to shut down. | 94 // Can be used to wait for this worker thread to shut down. |
68 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) | 95 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) |
69 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 96 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
70 | 97 |
(...skipping 20 matching lines...) Expand all Loading... |
91 | 118 |
92 // Number of active worker threads. | 119 // Number of active worker threads. |
93 static unsigned workerThreadCount(); | 120 static unsigned workerThreadCount(); |
94 | 121 |
95 PlatformThreadId platformThreadId() const; | 122 PlatformThreadId platformThreadId() const; |
96 | 123 |
97 void interruptAndDispatchInspectorCommands(); | 124 void interruptAndDispatchInspectorCommands(); |
98 void setWorkerInspectorController(WorkerInspectorController*); | 125 void setWorkerInspectorController(WorkerInspectorController*); |
99 | 126 |
100 protected: | 127 protected: |
| 128 int decrementAndReturnTaskCount(); |
| 129 void queueUpIdleHandlerNow(long long delayMs); |
| 130 int taskCount() { return m_tasksCount; } |
| 131 |
101 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBeRawP
tr<WorkerThreadStartupData>); | 132 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBeRawP
tr<WorkerThreadStartupData>); |
102 | 133 |
103 // Factory method for creating a new worker context for the thread. | 134 // Factory method for creating a new worker context for the thread. |
104 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; | 135 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
105 | 136 |
106 virtual void postInitialize() { } | 137 virtual void postInitialize() { } |
107 | 138 |
108 private: | 139 private: |
109 friend class WorkerSharedTimer; | 140 friend class WorkerSharedTimer; |
110 friend class WorkerThreadShutdownFinishTask; | 141 friend class WorkerThreadShutdownFinishTask; |
111 | 142 |
112 void stopInShutdownSequence(); | 143 void stopInShutdownSequence(); |
113 void stopInternal(); | 144 void stopInternal(); |
114 | 145 |
115 void initialize(); | 146 void initialize(); |
116 void cleanup(); | 147 void cleanup(); |
117 void idleHandler(); | 148 void idleHandler(); |
118 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); | 149 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); |
| 150 // Method returns true if the task is canceled & cleared, else returns false |
| 151 inline bool clearIdleHandlerTaskIfSet(); |
119 | 152 |
120 bool m_terminated; | 153 bool m_terminated; |
121 OwnPtr<WorkerSharedTimer> m_sharedTimer; | 154 OwnPtr<WorkerSharedTimer> m_sharedTimer; |
122 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; | 155 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; |
123 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 156 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
124 | 157 |
125 WorkerLoaderProxy& m_workerLoaderProxy; | 158 WorkerLoaderProxy& m_workerLoaderProxy; |
126 WorkerReportingProxy& m_workerReportingProxy; | 159 WorkerReportingProxy& m_workerReportingProxy; |
127 | 160 |
128 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; | 161 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; |
129 Mutex m_workerInspectorControllerMutex; | 162 Mutex m_workerInspectorControllerMutex; |
130 | 163 |
131 Mutex m_threadCreationMutex; | 164 Mutex m_threadCreationMutex; |
132 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 165 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
133 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; | 166 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; |
134 | 167 |
135 // Used to signal thread shutdown. | 168 // Used to signal thread shutdown. |
136 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 169 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
137 | 170 |
138 // Used to signal thread termination. | 171 // Used to signal thread termination. |
139 OwnPtr<WebWaitableEvent> m_terminationEvent; | 172 OwnPtr<WebWaitableEvent> m_terminationEvent; |
140 | 173 |
| 174 WorkerThreadTask* m_lastQueuedIdleHandlerTask; |
| 175 volatile int m_tasksCount; |
| 176 |
141 // FIXME: This has to be last because of crbug.com/401397 - the | 177 // FIXME: This has to be last because of crbug.com/401397 - the |
142 // WorkerThread might get deleted before it had a chance to properly | 178 // WorkerThread might get deleted before it had a chance to properly |
143 // shut down. By deleting the WebThread first, we can guarantee that | 179 // shut down. By deleting the WebThread first, we can guarantee that |
144 // no pending tasks on the thread might want to access any of the other | 180 // no pending tasks on the thread might want to access any of the other |
145 // members during the WorkerThread's destruction. | 181 // members during the WorkerThread's destruction. |
146 OwnPtr<WebThreadSupportingGC> m_thread; | 182 OwnPtr<WebThreadSupportingGC> m_thread; |
147 }; | 183 }; |
148 | 184 |
149 } // namespace blink | 185 } // namespace blink |
150 | 186 |
151 #endif // WorkerThread_h | 187 #endif // WorkerThread_h |
OLD | NEW |