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 namespace blink { | 8 namespace blink { |
9 | 9 |
10 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) | 10 namespace { |
11 { | |
12 return adoptPtr(new WebThreadSupportingGC(name)); | |
13 } | |
14 | 11 |
15 WebThreadSupportingGC::WebThreadSupportingGC(const char* name) | 12 class OwnWebThreadSupportingGC final : public WebThreadSupportingGC { |
| 13 WTF_MAKE_NONCOPYABLE(OwnWebThreadSupportingGC); |
| 14 public: |
| 15 explicit OwnWebThreadSupportingGC(const char* name); |
| 16 ~OwnWebThreadSupportingGC() override; |
| 17 |
| 18 private: |
| 19 WebThread& platformThread() const override |
| 20 { |
| 21 ASSERT(m_thread); |
| 22 return *m_thread; |
| 23 } |
| 24 // FIXME: This has to be last because of crbug.com/401397. |
| 25 // A WorkerThread might get deleted before it had a chance to properly |
| 26 // shut down. By deleting the WebThread first, we can guarantee that |
| 27 // no pending tasks on the thread might want to access any of the other |
| 28 // members during the WorkerThread's destruction. |
| 29 OwnPtr<WebThread> m_thread; |
| 30 }; |
| 31 |
| 32 OwnWebThreadSupportingGC::OwnWebThreadSupportingGC(const char* name) |
16 : m_thread(adoptPtr(Platform::current()->createThread(name))) | 33 : m_thread(adoptPtr(Platform::current()->createThread(name))) |
17 { | 34 { |
18 } | 35 } |
19 | 36 |
20 WebThreadSupportingGC::~WebThreadSupportingGC() | 37 OwnWebThreadSupportingGC::~OwnWebThreadSupportingGC() |
21 { | 38 { |
22 if (ThreadState::current()) { | 39 if (ThreadState::current()) { |
23 // WebThread's destructor blocks until all the tasks are processed. | 40 // WebThread's destructor blocks until all the tasks are processed. |
24 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); | 41 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); |
25 m_thread.clear(); | 42 m_thread.clear(); |
26 } | 43 } |
27 } | 44 } |
28 | 45 |
| 46 } // namespace |
| 47 |
| 48 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name
) |
| 49 { |
| 50 return adoptPtr(new OwnWebThreadSupportingGC(name)); |
| 51 } |
| 52 |
| 53 WebThreadSupportingGC::~WebThreadSupportingGC() |
| 54 { |
| 55 } |
| 56 |
29 void WebThreadSupportingGC::attachGC() | 57 void WebThreadSupportingGC::attachGC() |
30 { | 58 { |
| 59 ASSERT(platformThread().isCurrentThread()); |
31 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | 60 m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
32 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre
ad())); | 61 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre
ad())); |
33 platformThread().addTaskObserver(m_pendingGCRunner.get()); | 62 platformThread().addTaskObserver(m_pendingGCRunner.get()); |
34 ThreadState::attach(); | 63 ThreadState::attach(); |
35 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); | 64 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); |
36 } | 65 } |
37 | 66 |
38 void WebThreadSupportingGC::detachGC() | 67 void WebThreadSupportingGC::detachGC() |
39 { | 68 { |
| 69 ASSERT(platformThread().isCurrentThread()); |
40 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); | 70 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); |
41 ThreadState::detach(); | 71 ThreadState::detach(); |
42 platformThread().removeTaskObserver(m_pendingGCRunner.get()); | 72 platformThread().removeTaskObserver(m_pendingGCRunner.get()); |
43 m_pendingGCRunner = nullptr; | 73 m_pendingGCRunner = nullptr; |
44 m_messageLoopInterruptor = nullptr; | 74 m_messageLoopInterruptor = nullptr; |
45 } | 75 } |
46 | 76 |
47 } // namespace blink | 77 } // namespace blink |
OLD | NEW |