OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 WebThreadSupportingGC_h | 5 #ifndef WebThreadSupportingGC_h |
6 #define WebThreadSupportingGC_h | 6 #define WebThreadSupportingGC_h |
7 | 7 |
8 #include "platform/heap/GCTaskRunner.h" | 8 #include "platform/heap/GCTaskRunner.h" |
9 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
10 #include "public/platform/WebTaskRunner.h" | 10 #include "public/platform/WebTaskRunner.h" |
11 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
12 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
13 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
14 #include <memory> | 14 #include "wtf/OwnPtr.h" |
| 15 #include "wtf/PassOwnPtr.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 // WebThreadSupportingGC wraps a WebThread and adds support for attaching | 19 // WebThreadSupportingGC wraps a WebThread and adds support for attaching |
19 // to and detaching from the Blink GC infrastructure. The initialize method | 20 // to and detaching from the Blink GC infrastructure. The initialize method |
20 // must be called during initialization on the WebThread and before the | 21 // must be called during initialization on the WebThread and before the |
21 // thread allocates any objects managed by the Blink GC. The shutdown | 22 // thread allocates any objects managed by the Blink GC. The shutdown |
22 // method must be called on the WebThread during shutdown when the thread | 23 // method must be called on the WebThread during shutdown when the thread |
23 // no longer needs to access objects managed by the Blink GC. | 24 // no longer needs to access objects managed by the Blink GC. |
24 // | 25 // |
25 // WebThreadSupportingGC usually internally creates and owns WebThread unless | 26 // WebThreadSupportingGC usually internally creates and owns WebThread unless |
26 // an existing WebThread is given via createForThread. | 27 // an existing WebThread is given via createForThread. |
27 class PLATFORM_EXPORT WebThreadSupportingGC final { | 28 class PLATFORM_EXPORT WebThreadSupportingGC final { |
28 USING_FAST_MALLOC(WebThreadSupportingGC); | 29 USING_FAST_MALLOC(WebThreadSupportingGC); |
29 WTF_MAKE_NONCOPYABLE(WebThreadSupportingGC); | 30 WTF_MAKE_NONCOPYABLE(WebThreadSupportingGC); |
30 public: | 31 public: |
31 static std::unique_ptr<WebThreadSupportingGC> create(const char* name, bool
perThreadHeapEnabled = false); | 32 static PassOwnPtr<WebThreadSupportingGC> create(const char* name, bool perTh
readHeapEnabled = false); |
32 static std::unique_ptr<WebThreadSupportingGC> createForThread(WebThread*, bo
ol perThreadHeapEnabled = false); | 33 static PassOwnPtr<WebThreadSupportingGC> createForThread(WebThread*, bool pe
rThreadHeapEnabled = false); |
33 ~WebThreadSupportingGC(); | 34 ~WebThreadSupportingGC(); |
34 | 35 |
35 void postTask(const WebTraceLocation& location, std::unique_ptr<SameThreadCl
osure> task) | 36 void postTask(const WebTraceLocation& location, std::unique_ptr<SameThreadCl
osure> task) |
36 { | 37 { |
37 m_thread->getWebTaskRunner()->postTask(location, std::move(task)); | 38 m_thread->getWebTaskRunner()->postTask(location, std::move(task)); |
38 } | 39 } |
39 | 40 |
40 void postDelayedTask(const WebTraceLocation& location, std::unique_ptr<SameT
hreadClosure> task, long long delayMs) | 41 void postDelayedTask(const WebTraceLocation& location, std::unique_ptr<SameT
hreadClosure> task, long long delayMs) |
41 { | 42 { |
42 m_thread->getWebTaskRunner()->postDelayedTask(location, std::move(task),
delayMs); | 43 m_thread->getWebTaskRunner()->postDelayedTask(location, std::move(task),
delayMs); |
(...skipping 29 matching lines...) Expand all Loading... |
72 | 73 |
73 WebThread& platformThread() const | 74 WebThread& platformThread() const |
74 { | 75 { |
75 ASSERT(m_thread); | 76 ASSERT(m_thread); |
76 return *m_thread; | 77 return *m_thread; |
77 } | 78 } |
78 | 79 |
79 private: | 80 private: |
80 WebThreadSupportingGC(const char* name, WebThread*, bool perThreadHeapEnable
d); | 81 WebThreadSupportingGC(const char* name, WebThread*, bool perThreadHeapEnable
d); |
81 | 82 |
82 std::unique_ptr<GCTaskRunner> m_gcTaskRunner; | 83 OwnPtr<GCTaskRunner> m_gcTaskRunner; |
83 | 84 |
84 // m_thread is guaranteed to be non-null after this instance is constructed. | 85 // m_thread is guaranteed to be non-null after this instance is constructed. |
85 // m_owningThread is non-null unless this instance is constructed for an | 86 // m_owningThread is non-null unless this instance is constructed for an |
86 // existing thread via createForThread(). | 87 // existing thread via createForThread(). |
87 WebThread* m_thread = nullptr; | 88 WebThread* m_thread = nullptr; |
88 std::unique_ptr<WebThread> m_owningThread; | 89 OwnPtr<WebThread> m_owningThread; |
89 bool m_perThreadHeapEnabled; | 90 bool m_perThreadHeapEnabled; |
90 }; | 91 }; |
91 | 92 |
92 } // namespace blink | 93 } // namespace blink |
93 | 94 |
94 #endif | 95 #endif |
OLD | NEW |