Chromium Code Reviews| Index: third_party/WebKit/Source/core/workers/WorkerBackingThread.h |
| diff --git a/third_party/WebKit/Source/core/workers/WorkerBackingThread.h b/third_party/WebKit/Source/core/workers/WorkerBackingThread.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6764bd58521e4021e1d72c46baeba14df5718802 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/workers/WorkerBackingThread.h |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef WorkerBackingThread_h |
| +#define WorkerBackingThread_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "wtf/Forward.h" |
| +#include "wtf/OwnPtr.h" |
| +#include "wtf/PassOwnPtr.h" |
| +#include "wtf/ThreadingPrimitives.h" |
| +#include <v8.h> |
| + |
| +namespace blink { |
| + |
| +class WebThread; |
| +class WebThreadSupportingGC; |
| + |
| +class CORE_EXPORT WorkerBackingThread final { |
|
kinuko
2016/04/04 16:18:16
Could we have a nice class-level comment for this?
yhirano
2016/04/06 01:51:40
I wrote something, though I'm not sure if it's nic
|
| +public: |
| + static PassOwnPtr<WorkerBackingThread> create(const char* name) { return adoptPtr(new WorkerBackingThread(name, false)); } |
| + static PassOwnPtr<WorkerBackingThread> create(WebThread* thread) { return adoptPtr(new WorkerBackingThread(thread, false)); } |
| + |
| + // These are needed to suppress leak reports. See |
| + // https://crbug.com/590802 and https://crbug.com/v8/1428. |
| + static PassOwnPtr<WorkerBackingThread> createForTest(const char* name) { return adoptPtr(new WorkerBackingThread(name, true)); } |
| + static PassOwnPtr<WorkerBackingThread> createForTest(WebThread* thread) { return adoptPtr(new WorkerBackingThread(thread, true)); } |
| + |
| + ~WorkerBackingThread(); |
| + |
| + // attach() and detach() atacches and detatches Oilpan and V8 to / from |
|
kinuko
2016/04/04 16:18:16
nit:
atacches -> attaches
detatches -> detaches
yhirano
2016/04/06 01:51:40
Done.
|
| + // the caller worker script, respectively. attach() and detach() increments |
| + // and decrements m_workerScriptCount. attach() initializes Oilpan and V8 |
| + // when m_workerScriptCount is 0. detach() terminates Oilpan and V8 when |
| + // m_workerScriptCount is 1. A worker script must not call any function |
| + // after calling detach(). |
| + void attach(); |
| + void detach(); |
| + unsigned workerScriptCount() |
|
kinuko
2016/04/04 16:18:16
nit: put one empty line after detach() before work
yhirano
2016/04/06 01:51:40
Done.
|
| + { |
| + MutexLocker locker(m_mutex); |
| + return m_workerScriptCount; |
| + } |
| + |
| + WebThreadSupportingGC& backingThread() |
| + { |
| + ASSERT(m_backingThread); |
| + return *m_backingThread; |
| + } |
| + |
| + v8::Isolate* isolate() { return m_isolate; } |
| + |
| +private: |
| + WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); |
| + WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown); |
| + void initialize(); |
| + void shutdown(); |
| + |
| + Mutex m_mutex; |
| + OwnPtr<WebThreadSupportingGC> m_backingThread; |
| + v8::Isolate* m_isolate = nullptr; |
| + unsigned m_workerScriptCount = 0; |
|
nhiroki
2016/04/05 10:04:33
It'd be nice to have a comment about what |m_mutex
yhirano
2016/04/06 01:51:40
Done.
|
| + bool m_isOwningThread; |
| + bool m_shouldCallGCOnShutdown; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // WorkerBackingThread_h |