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