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..ebbec74ad3c65d5625694c733d5058e26aa6ee78 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/workers/WorkerBackingThread.h |
@@ -0,0 +1,67 @@ |
+// 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/PassRefPtr.h" |
+#include "wtf/RefCounted.h" |
+#include "wtf/ThreadingPrimitives.h" |
+#include <v8.h> |
+ |
+namespace blink { |
+ |
+class WebThread; |
+class WebThreadSupportingGC; |
+ |
+// Ref counting must be done in the main thread. |
+class CORE_EXPORT WorkerBackingThread final : public RefCounted<WorkerBackingThread> { |
+public: |
+ static PassRefPtr<WorkerBackingThread> create(const char* name) { return adoptRef(new WorkerBackingThread(name, false)); } |
+ static PassRefPtr<WorkerBackingThread> create(WebThread* thread) { return adoptRef(new WorkerBackingThread(thread, false)); } |
+ |
+ // These are needed to suppress leak reports. See |
+ // https://crbug.com/590802 and https://crbug.com/v8/1428. |
+ static PassRefPtr<WorkerBackingThread> createForTest(const char* name) { return adoptRef(new WorkerBackingThread(name, true)); } |
+ static PassRefPtr<WorkerBackingThread> createForTest(WebThread* thread) { return adoptRef(new WorkerBackingThread(thread, true)); } |
+ |
+ ~WorkerBackingThread(); |
+ |
+ void attach(); |
+ void detach(); |
kinuko
2016/03/30 16:03:05
nit: please have comments for attach/detach
yhirano
2016/03/31 08:29:11
Done.
|
+ unsigned workerScriptCount() |
+ { |
+ MutexLocker locker(m_mutex); |
+ return m_workerScriptCount; |
+ } |
+ |
+ WebThreadSupportingGC& backingThread() |
+ { |
+ ASSERT(m_backingThread); |
+ return *m_backingThread; |
+ } |
+ |
+ v8::Isolate* isolate() const { return m_isolate; } |
kinuko
2016/03/30 16:03:05
This pattern seems to have exist before your chang
yhirano
2016/03/31 08:29:11
That's funny, some reviewers prefer it and I was o
kinuko
2016/03/31 09:10:11
https://google.github.io/styleguide/cppguide.html#
|
+ |
+private: |
+ explicit WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); |
+ explicit WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown); |
kinuko
2016/03/30 16:03:05
nit: no need of explicit
yhirano
2016/03/31 08:29:11
Done.
|
+ void initialize(); |
+ void shutdown(); |
+ |
+ Mutex m_mutex; |
+ OwnPtr<WebThreadSupportingGC> m_backingThread; |
+ v8::Isolate* m_isolate = nullptr; |
+ unsigned m_workerScriptCount = 0; |
+ bool m_isOwningThread; |
+ bool m_shouldCallGCOnShutdown; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // WorkerBackingThread_h |