Chromium Code Reviews| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
| 11 #include "platform/heap/ThreadState.h" | 11 #include "platform/heap/ThreadState.h" |
| 12 #include "platform/wtf/Forward.h" | 12 #include "platform/wtf/Forward.h" |
| 13 #include "platform/wtf/PtrUtil.h" | 13 #include "platform/wtf/PtrUtil.h" |
| 14 #include "platform/wtf/ThreadingPrimitives.h" | 14 #include "platform/wtf/ThreadingPrimitives.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace scheduler { | |
| 20 class WorkerGlobalScopeScheduler; | |
| 21 } // namespace scheduler | |
| 22 | |
| 19 class WebThread; | 23 class WebThread; |
| 20 class WebThreadSupportingGC; | 24 class WebThreadSupportingGC; |
| 21 | 25 |
| 22 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially | 26 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially |
| 23 // shared by multiple WebWorker scripts. A WebWorker needs to call initialize() | 27 // shared by multiple WebWorker scripts. A WebWorker needs to call initialize() |
| 24 // to using V8 and Oilpan functionalities, and call shutdown() when the script | 28 // to using V8 and Oilpan functionalities, and call shutdown() when the script |
| 25 // no longer needs the thread. | 29 // no longer needs the thread. |
| 26 // A WorkerBackingThread represents a WebThread while a WorkerThread corresponds | 30 // A WorkerBackingThread represents a WebThread while a WorkerThread corresponds |
| 27 // to a web worker. There is one-to-one correspondence between WorkerThread and | 31 // to a web worker. There is one-to-one correspondence between WorkerThread and |
| 28 // WorkerGlobalScope, but multiple WorkerThreads (i.e., multiple | 32 // WorkerGlobalScope, but multiple WorkerThreads (i.e., multiple |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 47 | 51 |
| 48 ~WorkerBackingThread(); | 52 ~WorkerBackingThread(); |
| 49 | 53 |
| 50 // initialize() and shutdown() attaches and detaches Oilpan and V8 to / from | 54 // initialize() and shutdown() attaches and detaches Oilpan and V8 to / from |
| 51 // the caller worker script, respectively. A worker script must not call | 55 // the caller worker script, respectively. A worker script must not call |
| 52 // any function after calling shutdown(). | 56 // any function after calling shutdown(). |
| 53 // They should be called from |this| thread. | 57 // They should be called from |this| thread. |
| 54 void Initialize(); | 58 void Initialize(); |
| 55 void Shutdown(); | 59 void Shutdown(); |
| 56 | 60 |
| 61 std::unique_ptr<scheduler::WorkerGlobalScopeScheduler> | |
| 62 CreateGlobalScopeScheduler(); | |
|
haraken
2017/04/17 14:49:52
Shall we inline the method in WorkerThread::Initia
nhiroki
2017/04/18 05:34:38
Done.
| |
| 63 | |
| 57 WebThreadSupportingGC& BackingThread() { | 64 WebThreadSupportingGC& BackingThread() { |
| 58 DCHECK(backing_thread_); | 65 DCHECK(backing_thread_); |
| 59 return *backing_thread_; | 66 return *backing_thread_; |
| 60 } | 67 } |
| 61 | 68 |
| 62 v8::Isolate* GetIsolate() { return isolate_; } | 69 v8::Isolate* GetIsolate() { return isolate_; } |
| 63 | 70 |
| 64 static void MemoryPressureNotificationToWorkerThreadIsolates( | 71 static void MemoryPressureNotificationToWorkerThreadIsolates( |
| 65 v8::MemoryPressureLevel); | 72 v8::MemoryPressureLevel); |
| 66 | 73 |
| 67 static void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode); | 74 static void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode); |
| 68 | 75 |
| 69 private: | 76 private: |
| 70 WorkerBackingThread(const char* name, bool should_call_gc_on_shutdown); | 77 WorkerBackingThread(const char* name, bool should_call_gc_on_shutdown); |
| 71 WorkerBackingThread(WebThread*, bool should_call_gc_on_s_hutdown); | 78 WorkerBackingThread(WebThread*, bool should_call_gc_on_s_hutdown); |
| 72 | 79 |
| 73 std::unique_ptr<WebThreadSupportingGC> backing_thread_; | 80 std::unique_ptr<WebThreadSupportingGC> backing_thread_; |
| 74 v8::Isolate* isolate_ = nullptr; | 81 v8::Isolate* isolate_ = nullptr; |
| 75 bool is_owning_thread_; | 82 bool is_owning_thread_; |
| 76 bool should_call_gc_on_shutdown_; | 83 bool should_call_gc_on_shutdown_; |
| 77 }; | 84 }; |
| 78 | 85 |
| 79 } // namespace blink | 86 } // namespace blink |
| 80 | 87 |
| 81 #endif // WorkerBackingThread_h | 88 #endif // WorkerBackingThread_h |
| OLD | NEW |