| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WorkerBackingThread_h | 5 #ifndef WorkerBackingThread_h |
| 6 #define WorkerBackingThread_h | 6 #define WorkerBackingThread_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "wtf/Forward.h" | 9 #include "wtf/Forward.h" |
| 10 #include "wtf/OwnPtr.h" | 10 #include "wtf/OwnPtr.h" |
| 11 #include "wtf/PassOwnPtr.h" | 11 #include "wtf/PassOwnPtr.h" |
| 12 #include "wtf/ThreadingPrimitives.h" | 12 #include "wtf/ThreadingPrimitives.h" |
| 13 #include <v8.h> | 13 #include <v8.h> |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class WaitableEvent; |
| 17 class WebThread; | 18 class WebThread; |
| 18 class WebThreadSupportingGC; | 19 class WebThreadSupportingGC; |
| 19 | 20 |
| 20 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially | 21 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially |
| 21 // shared by multiple WebWorker scripts. A WebWorker needs to call attach() when | 22 // shared by multiple WebWorker scripts. A WebWorker needs to call attach() when |
| 22 // attaching itself to the backing thread, and call detach() when the script | 23 // attaching itself to the backing thread, and call detach() when the script |
| 23 // no longer needs the thread. | 24 // no longer needs the thread. |
| 24 // A WorkerBackingThread represents a WebThread while a WorkerThread corresponds | 25 // A WorkerBackingThread represents a WebThread while a WorkerThread corresponds |
| 25 // to a web worker. There is one-to-one correspondence between WorkerThread and | 26 // to a web worker. There is one-to-one correspondence between WorkerThread and |
| 26 // WorkerGlobalScope, but multiple WorkerThreads (i.e., multiple | 27 // WorkerGlobalScope, but multiple WorkerThreads (i.e., multiple |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DCHECK(m_backingThread); | 59 DCHECK(m_backingThread); |
| 59 return *m_backingThread; | 60 return *m_backingThread; |
| 60 } | 61 } |
| 61 | 62 |
| 62 v8::Isolate* isolate() { return m_isolate; } | 63 v8::Isolate* isolate() { return m_isolate; } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); | 66 WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); |
| 66 WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown); | 67 WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown); |
| 67 void initialize(); | 68 void initialize(); |
| 68 void shutdown(); | 69 void shutdown(WaitableEvent* doneEvent = nullptr); |
| 70 void signalShutdownAndWait(); |
| 69 | 71 |
| 70 // Protects |m_workerScriptCount|. | 72 // Protects |m_workerScriptCount|. |
| 71 Mutex m_mutex; | 73 Mutex m_mutex; |
| 72 OwnPtr<WebThreadSupportingGC> m_backingThread; | 74 OwnPtr<WebThreadSupportingGC> m_backingThread; |
| 73 v8::Isolate* m_isolate = nullptr; | 75 v8::Isolate* m_isolate = nullptr; |
| 74 unsigned m_workerScriptCount = 0; | 76 unsigned m_workerScriptCount = 0; |
| 75 bool m_isOwningThread; | 77 bool m_isOwningThread; |
| 76 bool m_shouldCallGCOnShutdown; | 78 bool m_shouldCallGCOnShutdown; |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 } // namespace blink | 81 } // namespace blink |
| 80 | 82 |
| 81 #endif // WorkerBackingThread_h | 83 #endif // WorkerBackingThread_h |
| OLD | NEW |