Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp

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

Powered by Google App Engine
This is Rietveld 408576698