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

Side by Side Diff: Source/modules/compositorworker/CompositorWorkerManager.cpp

Issue 1319363002: Makes WebThreadSupportingGC constructible for an existing thread (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/compositorworker/CompositorWorkerManager.h" 6 #include "modules/compositorworker/CompositorWorkerManager.h"
7 7
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8GCController.h" 9 #include "bindings/core/v8/V8GCController.h"
10 #include "bindings/core/v8/V8Initializer.h" 10 #include "bindings/core/v8/V8Initializer.h"
11 #include "bindings/core/v8/V8PerIsolateData.h" 11 #include "bindings/core/v8/V8PerIsolateData.h"
12 #include "platform/ThreadSafeFunctional.h" 12 #include "platform/ThreadSafeFunctional.h"
13 #include "platform/WebThreadSupportingGC.h" 13 #include "platform/WebThreadSupportingGC.h"
14 #include "wtf/MainThread.h" 14 #include "wtf/MainThread.h"
15 #include "wtf/ThreadingPrimitives.h" 15 #include "wtf/ThreadingPrimitives.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 namespace { 19 namespace {
20 20
21 static CompositorWorkerManager* s_instance = nullptr; 21 static CompositorWorkerManager* s_instance = nullptr;
22 22
23 static Mutex& singletonMutex() 23 Mutex& singletonMutex()
24 { 24 {
25 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex); 25 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex);
26 return mutex; 26 return mutex;
27 } 27 }
28 28
29 static void destroyThread(WebThreadSupportingGC* thread) 29 void destroyThread(WebThread* thread)
30 { 30 {
31 delete thread; 31 delete thread;
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 void CompositorWorkerManager::initialize() 36 void CompositorWorkerManager::initialize()
37 { 37 {
38 MutexLocker lock(singletonMutex()); 38 MutexLocker lock(singletonMutex());
39 ASSERT(!s_instance); 39 ASSERT(!s_instance);
(...skipping 22 matching lines...) Expand all
62 CompositorWorkerManager::~CompositorWorkerManager() 62 CompositorWorkerManager::~CompositorWorkerManager()
63 { 63 {
64 } 64 }
65 65
66 WebThreadSupportingGC& CompositorWorkerManager::compositorWorkerThread() 66 WebThreadSupportingGC& CompositorWorkerManager::compositorWorkerThread()
67 { 67 {
68 MutexLocker lock(m_mutex); 68 MutexLocker lock(m_mutex);
69 if (!m_thread) { 69 if (!m_thread) {
70 ASSERT(isMainThread()); 70 ASSERT(isMainThread());
71 ASSERT(!m_workerCount); 71 ASSERT(!m_workerCount);
72 m_thread = WebThreadSupportingGC::create("CompositorWorker Thread"); 72 // TODO(sadrul): Instead of creating a new thread, retrieve the thread f rom
73 // Platform using a more specialized function
74 // (e.g. Platform::compositorWorkerThread()).
75 m_platformThread = adoptPtr(Platform::current()->createThread("Composito rWorker Thread"));
76 m_thread = WebThreadSupportingGC::createForThread(m_platformThread.get() );
73 } 77 }
74 return *m_thread.get(); 78 return *m_thread.get();
75 } 79 }
76 80
77 void CompositorWorkerManager::initializeBackingThread() 81 void CompositorWorkerManager::initializeBackingThread()
78 { 82 {
79 ASSERT(m_thread->isCurrentThread()); 83 ASSERT(m_thread->isCurrentThread());
80 MutexLocker lock(m_mutex); 84 MutexLocker lock(m_mutex);
81 ++m_workerCount; 85 ++m_workerCount;
82 if (m_workerCount > 1) 86 if (m_workerCount > 1)
(...skipping 12 matching lines...) Expand all
95 } 99 }
96 100
97 void CompositorWorkerManager::shutdownBackingThread() 101 void CompositorWorkerManager::shutdownBackingThread()
98 { 102 {
99 MutexLocker lock(m_mutex); 103 MutexLocker lock(m_mutex);
100 ASSERT(m_thread->isCurrentThread()); 104 ASSERT(m_thread->isCurrentThread());
101 ASSERT(m_workerCount > 0); 105 ASSERT(m_workerCount > 0);
102 --m_workerCount; 106 --m_workerCount;
103 if (m_workerCount == 0) { 107 if (m_workerCount == 0) {
104 m_thread->shutdown(); 108 m_thread->shutdown();
105 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(de stroyThread, AllowCrossThreadAccess(m_thread.leakPtr()))); 109 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(de stroyThread, AllowCrossThreadAccess(m_platformThread.leakPtr())));
106 m_thread = nullptr; 110 m_thread = nullptr;
haraken 2015/09/01 09:32:37 Nit: We may want to run m_thread=nullptr before po
kinuko 2015/09/01 09:48:56 Done.
107 } 111 }
108 } 112 }
109 113
110 v8::Isolate* CompositorWorkerManager::initializeIsolate() 114 v8::Isolate* CompositorWorkerManager::initializeIsolate()
111 { 115 {
112 MutexLocker lock(m_mutex); 116 MutexLocker lock(m_mutex);
113 ASSERT(m_thread->isCurrentThread()); 117 ASSERT(m_thread->isCurrentThread());
114 ASSERT(m_isolate); 118 ASSERT(m_isolate);
115 // It is safe to use the existing isolate even if TerminateExecution() has b een 119 // It is safe to use the existing isolate even if TerminateExecution() has b een
116 // called on it, without calling CancelTerminateExecution(). 120 // called on it, without calling CancelTerminateExecution().
(...skipping 22 matching lines...) Expand all
139 { 143 {
140 MutexLocker lock(m_mutex); 144 MutexLocker lock(m_mutex);
141 ASSERT(isMainThread()); 145 ASSERT(isMainThread());
142 if (m_workerCount > 1) 146 if (m_workerCount > 1)
143 return; 147 return;
144 148
145 v8::V8::TerminateExecution(m_isolate); 149 v8::V8::TerminateExecution(m_isolate);
146 } 150 }
147 151
148 } // namespace blink 152 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698