Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WorkerBackingThread_h | |
| 6 #define WorkerBackingThread_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "wtf/Forward.h" | |
| 10 #include "wtf/OwnPtr.h" | |
| 11 #include "wtf/PassOwnPtr.h" | |
| 12 #include "wtf/ThreadingPrimitives.h" | |
| 13 #include <v8.h> | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 class WebThread; | |
| 18 class WebThreadSupportingGC; | |
| 19 | |
| 20 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially | |
| 21 // 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 // no longer needs the thread. | |
| 24 class CORE_EXPORT WorkerBackingThread final { | |
| 25 public: | |
| 26 static PassOwnPtr<WorkerBackingThread> create(const char* name) { return ado ptPtr(new WorkerBackingThread(name, false)); } | |
| 27 static PassOwnPtr<WorkerBackingThread> create(WebThread* thread) { return ad optPtr(new WorkerBackingThread(thread, false)); } | |
| 28 | |
| 29 // These are needed to suppress leak reports. See | |
| 30 // https://crbug.com/590802 and https://crbug.com/v8/1428. | |
| 31 static PassOwnPtr<WorkerBackingThread> createForTest(const char* name) { ret urn adoptPtr(new WorkerBackingThread(name, true)); } | |
| 32 static PassOwnPtr<WorkerBackingThread> createForTest(WebThread* thread) { re turn adoptPtr(new WorkerBackingThread(thread, true)); } | |
| 33 | |
| 34 ~WorkerBackingThread(); | |
| 35 | |
| 36 // attach() and detach() attaches and detaches Oilpan and V8 to / from | |
| 37 // the caller worker script, respectively. attach() and detach() increments | |
| 38 // and decrements m_workerScriptCount. attach() initializes Oilpan and V8 | |
| 39 // when m_workerScriptCount is 0. detach() terminates Oilpan and V8 when | |
| 40 // m_workerScriptCount is 1. A worker script must not call any function | |
| 41 // after calling detach(). | |
| 42 void attach(); | |
| 43 void detach(); | |
| 44 | |
| 45 unsigned workerScriptCount() | |
| 46 { | |
| 47 MutexLocker locker(m_mutex); | |
| 48 return m_workerScriptCount; | |
| 49 } | |
| 50 | |
| 51 WebThreadSupportingGC& backingThread() | |
| 52 { | |
| 53 ASSERT(m_backingThread); | |
| 54 return *m_backingThread; | |
| 55 } | |
| 56 | |
| 57 v8::Isolate* isolate() { return m_isolate; } | |
| 58 | |
| 59 private: | |
| 60 WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); | |
| 61 WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown); | |
| 62 void initialize(); | |
| 63 void shutdown(); | |
| 64 | |
| 65 // Protects |m_workerScriptCount|. | |
| 66 Mutex m_mutex; | |
| 67 OwnPtr<WebThreadSupportingGC> m_backingThread; | |
| 68 v8::Isolate* m_isolate = nullptr; | |
| 69 unsigned m_workerScriptCount = 0; | |
|
haraken
2016/04/06 09:23:17
m_workerScriptCount => m_attachedWorkerThreadCount
yhirano
2016/04/07 08:12:40
As in https://codereview.chromium.org/1728803002/,
| |
| 70 bool m_isOwningThread; | |
| 71 bool m_shouldCallGCOnShutdown; | |
| 72 }; | |
| 73 | |
| 74 } // namespace blink | |
| 75 | |
| 76 #endif // WorkerBackingThread_h | |
| OLD | NEW |