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