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

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

Issue 2355193002: Use enum for per thread heap enabled flag (Closed)
Patch Set: fix Created 4 years, 2 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/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(const char* name, bool perThreadHeapEnabled) 15 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name, BlinkGC::ThreadHeapMode threadHeapMode)
16 { 16 {
17 return wrapUnique(new WebThreadSupportingGC(name, nullptr, perThreadHeapEnab led)); 17 return wrapUnique(new WebThreadSupportingGC(name, nullptr, threadHeapMode));
18 } 18 }
19 19
20 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(We bThread* thread, bool perThreadHeapEnabled) 20 std::unique_ptr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(We bThread* thread, BlinkGC::ThreadHeapMode threadHeapMode)
21 { 21 {
22 return wrapUnique(new WebThreadSupportingGC(nullptr, thread, perThreadHeapEn abled)); 22 return wrapUnique(new WebThreadSupportingGC(nullptr, thread, threadHeapMode) );
23 } 23 }
24 24
25 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread , bool perThreadHeapEnabled) 25 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread , BlinkGC::ThreadHeapMode threadHeapMode)
26 : m_thread(thread) 26 : m_thread(thread)
27 , m_perThreadHeapEnabled(perThreadHeapEnabled) 27 , m_threadHeapMode(threadHeapMode)
28 { 28 {
29 #if ENABLE(ASSERT) 29 #if ENABLE(ASSERT)
30 ASSERT(!name || !thread); 30 ASSERT(!name || !thread);
31 // 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,
32 // 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.
33 WTF::willCreateThread(); 33 WTF::willCreateThread();
34 #endif 34 #endif
35 if (!m_thread) { 35 if (!m_thread) {
36 // 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.
37 m_owningThread = wrapUnique(Platform::current()->createThread(name)); 37 m_owningThread = wrapUnique(Platform::current()->createThread(name));
38 m_thread = m_owningThread.get(); 38 m_thread = m_owningThread.get();
39 } 39 }
40 } 40 }
41 41
42 WebThreadSupportingGC::~WebThreadSupportingGC() 42 WebThreadSupportingGC::~WebThreadSupportingGC()
43 { 43 {
44 if (ThreadState::current() && m_owningThread) { 44 if (ThreadState::current() && m_owningThread) {
45 // WebThread's destructor blocks until all the tasks are processed. 45 // WebThread's destructor blocks until all the tasks are processed.
46 SafePointScope scope(BlinkGC::HeapPointersOnStack); 46 SafePointScope scope(BlinkGC::HeapPointersOnStack);
47 m_owningThread.reset(); 47 m_owningThread.reset();
48 } 48 }
49 } 49 }
50 50
51 void WebThreadSupportingGC::initialize() 51 void WebThreadSupportingGC::initialize()
52 { 52 {
53 ThreadState::attachCurrentThread(m_perThreadHeapEnabled); 53 ThreadState::attachCurrentThread(m_threadHeapMode);
54 m_gcTaskRunner = wrapUnique(new GCTaskRunner(m_thread)); 54 m_gcTaskRunner = wrapUnique(new GCTaskRunner(m_thread));
55 } 55 }
56 56
57 void WebThreadSupportingGC::shutdown() 57 void WebThreadSupportingGC::shutdown()
58 { 58 {
59 #if defined(LEAK_SANITIZER) 59 #if defined(LEAK_SANITIZER)
60 ThreadState::current()->releaseStaticPersistentNodes(); 60 ThreadState::current()->releaseStaticPersistentNodes();
61 #endif 61 #endif
62 // Ensure no posted tasks will run from this point on. 62 // Ensure no posted tasks will run from this point on.
63 m_gcTaskRunner.reset(); 63 m_gcTaskRunner.reset();
64 64
65 // 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
66 // and is owned by this instance. 66 // and is owned by this instance.
67 if (m_owningThread) 67 if (m_owningThread)
68 m_owningThread->scheduler()->shutdown(); 68 m_owningThread->scheduler()->shutdown();
69 69
70 ThreadState::detachCurrentThread(); 70 ThreadState::detachCurrentThread();
71 } 71 }
72 72
73 } // namespace blink 73 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/WebThreadSupportingGC.h ('k') | third_party/WebKit/Source/platform/heap/BlinkGC.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698