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 #include "config.h" | 5 #include "config.h" |
6 #include "platform/WebThreadSupportingGC.h" | 6 #include "platform/WebThreadSupportingGC.h" |
7 | 7 |
8 #include "platform/heap/SafePoint.h" | 8 #include "platform/heap/SafePoint.h" |
9 #include "public/platform/WebScheduler.h" | |
10 #include "wtf/Threading.h" | 9 #include "wtf/Threading.h" |
11 | 10 |
12 namespace blink { | 11 namespace blink { |
13 | 12 |
14 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) | 13 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) |
15 { | 14 { |
16 #if ENABLE(ASSERT) | 15 #if ENABLE(ASSERT) |
17 WTF::willCreateThread(); | 16 WTF::willCreateThread(); |
18 #endif | 17 #endif |
19 return adoptPtr(new WebThreadSupportingGC(name)); | 18 return adoptPtr(new WebThreadSupportingGC(name)); |
20 } | 19 } |
21 | 20 |
22 WebThreadSupportingGC::WebThreadSupportingGC(const char* name) | 21 WebThreadSupportingGC::WebThreadSupportingGC(const char* name) |
23 : m_thread(adoptPtr(Platform::current()->createThread(name))) | 22 : m_thread(adoptPtr(Platform::current()->createThread(name))) |
24 { | 23 { |
25 } | 24 } |
26 | 25 |
27 WebThreadSupportingGC::~WebThreadSupportingGC() | 26 WebThreadSupportingGC::~WebThreadSupportingGC() |
28 { | 27 { |
29 if (ThreadState::current()) { | 28 if (ThreadState::current()) { |
30 // WebThread's destructor blocks until all the tasks are processed. | 29 // WebThread's destructor blocks until all the tasks are processed. |
31 SafePointScope scope(ThreadState::HeapPointersOnStack); | 30 SafePointScope scope(ThreadState::HeapPointersOnStack); |
32 m_thread.clear(); | 31 m_thread.clear(); |
33 } | 32 } |
34 } | 33 } |
35 | 34 |
36 void WebThreadSupportingGC::initialize() | 35 void WebThreadSupportingGC::attachGC() |
37 { | 36 { |
38 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | 37 m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
39 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre
ad())); | 38 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre
ad())); |
40 platformThread().addTaskObserver(m_pendingGCRunner.get()); | 39 platformThread().addTaskObserver(m_pendingGCRunner.get()); |
41 ThreadState::attach(); | 40 ThreadState::attach(); |
42 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); | 41 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); |
43 } | 42 } |
44 | 43 |
45 void WebThreadSupportingGC::shutdown() | 44 void WebThreadSupportingGC::detachGC() |
46 { | 45 { |
47 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); | 46 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); |
48 ThreadState::detach(); | 47 ThreadState::detach(); |
49 platformThread().removeTaskObserver(m_pendingGCRunner.get()); | 48 platformThread().removeTaskObserver(m_pendingGCRunner.get()); |
50 m_pendingGCRunner = nullptr; | 49 m_pendingGCRunner = nullptr; |
51 m_messageLoopInterruptor = nullptr; | 50 m_messageLoopInterruptor = nullptr; |
52 | |
53 // Ensure no posted tasks will run from this point on. | |
54 platformThread().scheduler()->shutdown(); | |
55 } | 51 } |
56 | 52 |
57 } // namespace blink | 53 } // namespace blink |
OLD | NEW |