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/PassRefPtr.h" | |
13 #include "wtf/RefCounted.h" | |
14 #include "wtf/ThreadingPrimitives.h" | |
15 #include <v8.h> | |
16 | |
17 namespace blink { | |
18 | |
19 class WebThread; | |
20 class WebThreadSupportingGC; | |
21 | |
22 // Ref counting must be done in the main thread. | |
23 class CORE_EXPORT WorkerBackingThread final : public RefCounted<WorkerBackingThr ead> { | |
24 public: | |
25 static PassRefPtr<WorkerBackingThread> create(const char* name) { return ado ptRef(new WorkerBackingThread(name, false)); } | |
26 static PassRefPtr<WorkerBackingThread> create(WebThread* thread) { return ad optRef(new WorkerBackingThread(thread, false)); } | |
27 | |
28 // These are needed to suppress leak reports. See | |
29 // https://crbug.com/590802 and https://crbug.com/v8/1428. | |
30 static PassRefPtr<WorkerBackingThread> createForTest(const char* name) { ret urn adoptRef(new WorkerBackingThread(name, true)); } | |
31 static PassRefPtr<WorkerBackingThread> createForTest(WebThread* thread) { re turn adoptRef(new WorkerBackingThread(thread, true)); } | |
32 | |
33 ~WorkerBackingThread(); | |
34 | |
35 void attach(); | |
36 void detach(); | |
kinuko
2016/03/30 16:03:05
nit: please have comments for attach/detach
yhirano
2016/03/31 08:29:11
Done.
| |
37 unsigned workerScriptCount() | |
38 { | |
39 MutexLocker locker(m_mutex); | |
40 return m_workerScriptCount; | |
41 } | |
42 | |
43 WebThreadSupportingGC& backingThread() | |
44 { | |
45 ASSERT(m_backingThread); | |
46 return *m_backingThread; | |
47 } | |
48 | |
49 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#
| |
50 | |
51 private: | |
52 explicit WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown); | |
53 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.
| |
54 void initialize(); | |
55 void shutdown(); | |
56 | |
57 Mutex m_mutex; | |
58 OwnPtr<WebThreadSupportingGC> m_backingThread; | |
59 v8::Isolate* m_isolate = nullptr; | |
60 unsigned m_workerScriptCount = 0; | |
61 bool m_isOwningThread; | |
62 bool m_shouldCallGCOnShutdown; | |
63 }; | |
64 | |
65 } // namespace blink | |
66 | |
67 #endif // WorkerBackingThread_h | |
OLD | NEW |