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

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

Issue 1477023003: Refactor the Heap into ThreadHeap to prepare for per thread heaps Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 "config.h" 5 #include "config.h"
6 #include "platform/WebThreadSupportingGC.h" 6 #include "platform/WebThreadSupportingGC.h"
7 7
8 #include "platform/heap/SafePoint.h" 8 #include "platform/heap/SafePoint.h"
9 #include "public/platform/WebScheduler.h" 9 #include "public/platform/WebScheduler.h"
10 #include "wtf/Threading.h" 10 #include "wtf/Threading.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name ) 14 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name , bool isolated)
15 { 15 {
16 return adoptPtr(new WebThreadSupportingGC(name, nullptr)); 16 return adoptPtr(new WebThreadSupportingGC(name, nullptr, isolated));
17 } 17 }
18 18
19 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(WebThre ad* thread) 19 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(WebThre ad* thread, bool isolated)
20 { 20 {
21 return adoptPtr(new WebThreadSupportingGC(nullptr, thread)); 21 return adoptPtr(new WebThreadSupportingGC(nullptr, thread, isolated));
22 } 22 }
23 23
24 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread ) 24 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread , bool isolated)
25 : m_thread(thread) 25 : m_thread(thread)
26 , m_isolated(isolated)
26 { 27 {
27 #if ENABLE(ASSERT) 28 #if ENABLE(ASSERT)
28 ASSERT(!name || !thread); 29 ASSERT(!name || !thread);
29 // We call this regardless of whether an existing thread is given or not, 30 // 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. 31 // as it means that blink is going to run with more than one thread.
31 WTF::willCreateThread(); 32 WTF::willCreateThread();
32 #endif 33 #endif
33 if (!m_thread) { 34 if (!m_thread) {
34 // If |thread| is not given, create a new one and own it. 35 // If |thread| is not given, create a new one and own it.
35 m_owningThread = adoptPtr(Platform::current()->createThread(name)); 36 m_owningThread = adoptPtr(Platform::current()->createThread(name));
36 m_thread = m_owningThread.get(); 37 m_thread = m_owningThread.get();
37 } 38 }
38 } 39 }
39 40
40 WebThreadSupportingGC::~WebThreadSupportingGC() 41 WebThreadSupportingGC::~WebThreadSupportingGC()
41 { 42 {
42 if (ThreadState::current() && m_owningThread) { 43 if (ThreadState::current() && m_owningThread) {
43 // WebThread's destructor blocks until all the tasks are processed. 44 // WebThread's destructor blocks until all the tasks are processed.
44 SafePointScope scope(BlinkGC::HeapPointersOnStack); 45 SafePointScope scope(BlinkGC::HeapPointersOnStack);
45 m_owningThread.clear(); 46 m_owningThread.clear();
46 } 47 }
47 } 48 }
48 49
49 void WebThreadSupportingGC::initialize() 50 void WebThreadSupportingGC::initialize()
50 { 51 {
51 ThreadState::attach(); 52 ThreadState::attach();
53 ThreadState::current()->setIsolated(m_isolated);
52 m_gcTaskRunner = adoptPtr(new GCTaskRunner(m_thread)); 54 m_gcTaskRunner = adoptPtr(new GCTaskRunner(m_thread));
53 } 55 }
54 56
55 void WebThreadSupportingGC::shutdown() 57 void WebThreadSupportingGC::shutdown()
56 { 58 {
57 // Ensure no posted tasks will run from this point on. 59 // Ensure no posted tasks will run from this point on.
58 m_gcTaskRunner.clear(); 60 m_gcTaskRunner.clear();
59 61
60 // Shutdown the thread (via its scheduler) only when the thread is created 62 // Shutdown the thread (via its scheduler) only when the thread is created
61 // and is owned by this instance. 63 // and is owned by this instance.
62 if (m_owningThread) 64 if (m_owningThread)
63 m_owningThread->scheduler()->shutdown(); 65 m_owningThread->scheduler()->shutdown();
64 66
65 ThreadState::detach(); 67 ThreadState::detach();
66 } 68 }
67 69
68 } // namespace blink 70 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698