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 "public/platform/WebScheduler.h" |
10 #include "wtf/Threading.h" | 10 #include "wtf/Threading.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
| 14 PassOwnPtr<GCSupportForWebThread> GCSupportForWebThread::create(WebThread& threa
d) |
| 15 { |
| 16 return adoptPtr(new GCSupportForWebThread(thread)); |
| 17 } |
| 18 |
| 19 GCSupportForWebThread::GCSupportForWebThread(WebThread& thread) |
| 20 : m_thread(thread) |
| 21 { |
| 22 m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
| 23 m_thread.addTaskObserver(m_pendingGCRunner.get()); |
| 24 ThreadState::attach(); |
| 25 OwnPtr<MessageLoopInterruptor> interruptor = adoptPtr(new MessageLoopInterru
ptor(&m_thread)); |
| 26 ThreadState::current()->addInterruptor(interruptor.release()); |
| 27 } |
| 28 |
| 29 GCSupportForWebThread::~GCSupportForWebThread() |
| 30 { |
| 31 m_thread.removeTaskObserver(m_pendingGCRunner.get()); |
| 32 |
| 33 ThreadState::detach(); |
| 34 m_pendingGCRunner = nullptr; |
| 35 } |
| 36 |
14 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) | 37 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) |
15 { | 38 { |
16 #if ENABLE(ASSERT) | 39 #if ENABLE(ASSERT) |
17 WTF::willCreateThread(); | 40 WTF::willCreateThread(); |
18 #endif | 41 #endif |
19 return adoptPtr(new WebThreadSupportingGC(name)); | 42 return adoptPtr(new WebThreadSupportingGC(name)); |
20 } | 43 } |
21 | 44 |
22 WebThreadSupportingGC::WebThreadSupportingGC(const char* name) | 45 WebThreadSupportingGC::WebThreadSupportingGC(const char* name) |
23 : m_thread(adoptPtr(Platform::current()->createThread(name))) | 46 : m_thread(adoptPtr(Platform::current()->createThread(name))) |
24 { | 47 { |
25 } | 48 } |
26 | 49 |
27 WebThreadSupportingGC::~WebThreadSupportingGC() | 50 WebThreadSupportingGC::~WebThreadSupportingGC() |
28 { | 51 { |
29 if (ThreadState::current()) { | 52 if (ThreadState::current()) { |
30 // WebThread's destructor blocks until all the tasks are processed. | 53 // WebThread's destructor blocks until all the tasks are processed. |
31 SafePointScope scope(ThreadState::HeapPointersOnStack); | 54 SafePointScope scope(ThreadState::HeapPointersOnStack); |
32 m_thread.clear(); | 55 m_thread.clear(); |
33 } | 56 } |
34 } | 57 } |
35 | 58 |
36 void WebThreadSupportingGC::initialize() | 59 void WebThreadSupportingGC::initialize() |
37 { | 60 { |
38 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | 61 m_gcSupport = GCSupportForWebThread::create(platformThread()); |
39 platformThread().addTaskObserver(m_pendingGCRunner.get()); | |
40 ThreadState::attach(); | |
41 OwnPtr<MessageLoopInterruptor> interruptor = adoptPtr(new MessageLoopInterru
ptor(&platformThread())); | |
42 ThreadState::current()->addInterruptor(interruptor.release()); | |
43 } | 62 } |
44 | 63 |
45 void WebThreadSupportingGC::shutdown() | 64 void WebThreadSupportingGC::shutdown() |
46 { | 65 { |
47 // Ensure no posted tasks will run from this point on. | 66 // Ensure no posted tasks will run from this point on. |
48 platformThread().removeTaskObserver(m_pendingGCRunner.get()); | |
49 platformThread().scheduler()->shutdown(); | 67 platformThread().scheduler()->shutdown(); |
50 | 68 m_gcSupport.clear(); |
51 ThreadState::detach(); | |
52 m_pendingGCRunner = nullptr; | |
53 } | 69 } |
54 | 70 |
55 } // namespace blink | 71 } // namespace blink |
OLD | NEW |