| OLD | NEW |
| 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 "modules/compositorworker/CompositorWorkerThread.h" | 5 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8GCController.h" | 7 #include "bindings/core/v8/V8GCController.h" |
| 8 #include "bindings/core/v8/V8Initializer.h" | 8 #include "bindings/core/v8/V8Initializer.h" |
| 9 #include "core/workers/InProcessWorkerObjectProxy.h" | 9 #include "core/workers/InProcessWorkerObjectProxy.h" |
| 10 #include "core/workers/WorkerBackingThread.h" | 10 #include "core/workers/WorkerBackingThread.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); | 59 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); |
| 60 } | 60 } |
| 61 | 61 |
| 62 WorkerBackingThread* thread() { return m_thread.get(); } | 62 WorkerBackingThread* thread() { return m_thread.get(); } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 BackingThreadHolder(std::unique_ptr<WorkerBackingThread> useBackingThread =
nullptr) | 65 BackingThreadHolder(std::unique_ptr<WorkerBackingThread> useBackingThread =
nullptr) |
| 66 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) | 66 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) |
| 67 { | 67 { |
| 68 DCHECK(isMainThread()); | 68 DCHECK(isMainThread()); |
| 69 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, AllowCrossThreadAccess(this))); | 69 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, crossThreadUnretained(this))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 static Mutex& holderInstanceMutex() | 72 static Mutex& holderInstanceMutex() |
| 73 { | 73 { |
| 74 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); | 74 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); |
| 75 return holderMutex; | 75 return holderMutex; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void initializeOnThread() | 78 void initializeOnThread() |
| 79 { | 79 { |
| 80 MutexLocker locker(holderInstanceMutex()); | 80 MutexLocker locker(holderInstanceMutex()); |
| 81 DCHECK(!m_initialized); | 81 DCHECK(!m_initialized); |
| 82 m_thread->initialize(); | 82 m_thread->initialize(); |
| 83 m_initialized = true; | 83 m_initialized = true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void shutdownAndWait() | 86 void shutdownAndWait() |
| 87 { | 87 { |
| 88 DCHECK(isMainThread()); | 88 DCHECK(isMainThread()); |
| 89 WaitableEvent doneEvent; | 89 WaitableEvent doneEvent; |
| 90 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::shutdownOnThread, AllowCrossThreadAccess(this), AllowCrossThrea
dAccess(&doneEvent))); | 90 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::shutdownOnThread, crossThreadUnretained(this), crossThreadUnret
ained(&doneEvent))); |
| 91 doneEvent.wait(); | 91 doneEvent.wait(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void shutdownOnThread(WaitableEvent* doneEvent) | 94 void shutdownOnThread(WaitableEvent* doneEvent) |
| 95 { | 95 { |
| 96 m_thread->shutdown(); | 96 m_thread->shutdown(); |
| 97 doneEvent->signal(); | 97 doneEvent->signal(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 std::unique_ptr<WorkerBackingThread> m_thread; | 100 std::unique_ptr<WorkerBackingThread> m_thread; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DCHECK(isMainThread()); | 147 DCHECK(isMainThread()); |
| 148 BackingThreadHolder::clear(); | 148 BackingThreadHolder::clear(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void CompositorWorkerThread::createSharedBackingThreadForTest() | 151 void CompositorWorkerThread::createSharedBackingThreadForTest() |
| 152 { | 152 { |
| 153 BackingThreadHolder::createForTest(); | 153 BackingThreadHolder::createForTest(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |