| 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 "platform/WebThreadSupportingGC.h" | 5 #include "platform/WebThreadSupportingGC.h" |
| 6 | 6 |
| 7 #include "platform/heap/SafePoint.h" | 7 #include "platform/heap/SafePoint.h" |
| 8 #include "public/platform/WebScheduler.h" | 8 #include "public/platform/WebScheduler.h" |
| 9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
| 10 #include "wtf/Threading.h" | 10 #include "wtf/Threading.h" |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::create( | 15 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::create( |
| 16 const char* name, | 16 const char* name, |
| 17 BlinkGC::ThreadHeapMode threadHeapMode) { | 17 BlinkGC::ThreadHeapMode threadHeapMode) { |
| 18 return wrapUnique(new WebThreadSupportingGC(name, nullptr, threadHeapMode)); | 18 return WTF::wrapUnique( |
| 19 new WebThreadSupportingGC(name, nullptr, threadHeapMode)); |
| 19 } | 20 } |
| 20 | 21 |
| 21 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread( | 22 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread( |
| 22 WebThread* thread, | 23 WebThread* thread, |
| 23 BlinkGC::ThreadHeapMode threadHeapMode) { | 24 BlinkGC::ThreadHeapMode threadHeapMode) { |
| 24 return wrapUnique(new WebThreadSupportingGC(nullptr, thread, threadHeapMode)); | 25 return WTF::wrapUnique( |
| 26 new WebThreadSupportingGC(nullptr, thread, threadHeapMode)); |
| 25 } | 27 } |
| 26 | 28 |
| 27 WebThreadSupportingGC::WebThreadSupportingGC( | 29 WebThreadSupportingGC::WebThreadSupportingGC( |
| 28 const char* name, | 30 const char* name, |
| 29 WebThread* thread, | 31 WebThread* thread, |
| 30 BlinkGC::ThreadHeapMode threadHeapMode) | 32 BlinkGC::ThreadHeapMode threadHeapMode) |
| 31 : m_thread(thread), m_threadHeapMode(threadHeapMode) { | 33 : m_thread(thread), m_threadHeapMode(threadHeapMode) { |
| 32 DCHECK(!name || !thread); | 34 DCHECK(!name || !thread); |
| 33 #if DCHECK_IS_ON() | 35 #if DCHECK_IS_ON() |
| 34 // We call this regardless of whether an existing thread is given or not, | 36 // We call this regardless of whether an existing thread is given or not, |
| 35 // as it means that blink is going to run with more than one thread. | 37 // as it means that blink is going to run with more than one thread. |
| 36 WTF::willCreateThread(); | 38 WTF::willCreateThread(); |
| 37 #endif | 39 #endif |
| 38 if (!m_thread) { | 40 if (!m_thread) { |
| 39 // If |thread| is not given, create a new one and own it. | 41 // If |thread| is not given, create a new one and own it. |
| 40 m_owningThread = wrapUnique(Platform::current()->createThread(name)); | 42 m_owningThread = WTF::wrapUnique(Platform::current()->createThread(name)); |
| 41 m_thread = m_owningThread.get(); | 43 m_thread = m_owningThread.get(); |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 WebThreadSupportingGC::~WebThreadSupportingGC() { | 47 WebThreadSupportingGC::~WebThreadSupportingGC() { |
| 46 if (ThreadState::current() && m_owningThread) { | 48 if (ThreadState::current() && m_owningThread) { |
| 47 // WebThread's destructor blocks until all the tasks are processed. | 49 // WebThread's destructor blocks until all the tasks are processed. |
| 48 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 50 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 49 m_owningThread.reset(); | 51 m_owningThread.reset(); |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 void WebThreadSupportingGC::initialize() { | 55 void WebThreadSupportingGC::initialize() { |
| 54 ThreadState::attachCurrentThread(m_threadHeapMode); | 56 ThreadState::attachCurrentThread(m_threadHeapMode); |
| 55 m_gcTaskRunner = makeUnique<GCTaskRunner>(m_thread); | 57 m_gcTaskRunner = WTF::makeUnique<GCTaskRunner>(m_thread); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void WebThreadSupportingGC::shutdown() { | 60 void WebThreadSupportingGC::shutdown() { |
| 59 #if defined(LEAK_SANITIZER) | 61 #if defined(LEAK_SANITIZER) |
| 60 ThreadState::current()->releaseStaticPersistentNodes(); | 62 ThreadState::current()->releaseStaticPersistentNodes(); |
| 61 #endif | 63 #endif |
| 62 // Ensure no posted tasks will run from this point on. | 64 // Ensure no posted tasks will run from this point on. |
| 63 m_gcTaskRunner.reset(); | 65 m_gcTaskRunner.reset(); |
| 64 | 66 |
| 65 // Shutdown the thread (via its scheduler) only when the thread is created | 67 // Shutdown the thread (via its scheduler) only when the thread is created |
| 66 // and is owned by this instance. | 68 // and is owned by this instance. |
| 67 if (m_owningThread) | 69 if (m_owningThread) |
| 68 m_owningThread->scheduler()->shutdown(); | 70 m_owningThread->scheduler()->shutdown(); |
| 69 | 71 |
| 70 ThreadState::detachCurrentThread(); | 72 ThreadState::detachCurrentThread(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 } // namespace blink | 75 } // namespace blink |
| OLD | NEW |