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

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

Issue 1274023003: compositor-worker: Get the thread to run compositor-workers from the Platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 4 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 static 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 static 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 16 matching lines...) Expand all
56 } 56 }
57 57
58 CompositorWorkerManager::CompositorWorkerManager() 58 CompositorWorkerManager::CompositorWorkerManager()
59 { 59 {
60 } 60 }
61 61
62 CompositorWorkerManager::~CompositorWorkerManager() 62 CompositorWorkerManager::~CompositorWorkerManager()
63 { 63 {
64 } 64 }
65 65
66 WebThreadSupportingGC& CompositorWorkerManager::compositorWorkerThread() 66 WebThread& 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(sad): Instead of creating a new thread, retrieve the thread from Platform using a more
73 // specialized function (e.g. Platform::comositorWorkerThread()).
74 m_thread = adoptPtr(Platform::current()->createThread("CompositorWorker Thread"));
73 } 75 }
74 return *m_thread.get(); 76 return *m_thread;
75 } 77 }
76 78
77 void CompositorWorkerManager::initializeBackingThread() 79 void CompositorWorkerManager::initializeBackingThread()
78 { 80 {
79 ASSERT(m_thread->isCurrentThread()); 81 ASSERT(m_thread->isCurrentThread());
80 MutexLocker lock(m_mutex); 82 MutexLocker lock(m_mutex);
81 ++m_workerCount; 83 ++m_workerCount;
82 if (m_workerCount > 1) 84 if (m_workerCount > 1)
83 return; 85 return;
84 86
85 m_thread->initialize(); 87 ASSERT(!m_gcSupport);
88 m_gcSupport = GCSupportForWebThread::create(*m_thread);
86 89
87 // Initialize the isolate at the same time. 90 // Initialize the isolate at the same time.
88 ASSERT(!m_isolate); 91 ASSERT(!m_isolate);
89 m_isolate = V8PerIsolateData::initialize(); 92 m_isolate = V8PerIsolateData::initialize();
90 V8Initializer::initializeWorker(m_isolate); 93 V8Initializer::initializeWorker(m_isolate);
91 94
92 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (m_isolate)); 95 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (m_isolate));
93 ThreadState::current()->addInterruptor(interruptor.release()); 96 ThreadState::current()->addInterruptor(interruptor.release());
94 ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController:: traceDOMWrappers); 97 ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController:: traceDOMWrappers);
95 } 98 }
96 99
97 void CompositorWorkerManager::shutdownBackingThread() 100 void CompositorWorkerManager::shutdownBackingThread()
98 { 101 {
99 MutexLocker lock(m_mutex); 102 MutexLocker lock(m_mutex);
100 ASSERT(m_thread->isCurrentThread()); 103 ASSERT(m_thread->isCurrentThread());
101 ASSERT(m_workerCount > 0); 104 ASSERT(m_workerCount > 0);
102 --m_workerCount; 105 --m_workerCount;
103 if (m_workerCount == 0) { 106 if (m_workerCount == 0) {
104 m_thread->shutdown(); 107 m_gcSupport.clear();
105 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(de stroyThread, AllowCrossThreadAccess(m_thread.leakPtr()))); 108 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(de stroyThread, AllowCrossThreadAccess(m_thread.leakPtr())));
106 m_thread = nullptr; 109 m_thread = nullptr;
107 } 110 }
108 } 111 }
109 112
110 v8::Isolate* CompositorWorkerManager::initializeIsolate() 113 v8::Isolate* CompositorWorkerManager::initializeIsolate()
111 { 114 {
112 MutexLocker lock(m_mutex); 115 MutexLocker lock(m_mutex);
113 ASSERT(m_thread->isCurrentThread()); 116 ASSERT(m_thread->isCurrentThread());
114 ASSERT(m_isolate); 117 ASSERT(m_isolate);
(...skipping 24 matching lines...) Expand all
139 { 142 {
140 MutexLocker lock(m_mutex); 143 MutexLocker lock(m_mutex);
141 ASSERT(isMainThread()); 144 ASSERT(isMainThread());
142 if (m_workerCount > 1) 145 if (m_workerCount > 1)
143 return; 146 return;
144 147
145 v8::V8::TerminateExecution(m_isolate); 148 v8::V8::TerminateExecution(m_isolate);
146 } 149 }
147 150
148 } // namespace blink 151 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698