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