Index: Source/platform/WebThreadSupportingGC.cpp |
diff --git a/Source/platform/WebThreadSupportingGC.cpp b/Source/platform/WebThreadSupportingGC.cpp |
index f2aec3e1addf011c63eaf4c1a887c67e01faa58e..99cc072f390c78c7da821c0b7bca3edc9346de6b 100644 |
--- a/Source/platform/WebThreadSupportingGC.cpp |
+++ b/Source/platform/WebThreadSupportingGC.cpp |
@@ -13,15 +13,28 @@ namespace blink { |
PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name) |
{ |
+ return adoptPtr(new WebThreadSupportingGC(name, nullptr)); |
+} |
+ |
+PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(WebThread* thread) |
+{ |
+ return adoptPtr(new WebThreadSupportingGC(nullptr, thread)); |
+} |
+ |
+WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread) |
+ : m_thread(thread) |
+{ |
#if ENABLE(ASSERT) |
+ ASSERT(!name || !thread); |
+ // We call this regardless of whether an existing thread is given or not, |
+ // as it means that blink is going to run with more than one thread. |
WTF::willCreateThread(); |
#endif |
- return adoptPtr(new WebThreadSupportingGC(name)); |
-} |
- |
-WebThreadSupportingGC::WebThreadSupportingGC(const char* name) |
- : m_thread(adoptPtr(Platform::current()->createThread(name))) |
-{ |
+ if (!m_thread) { |
+ // If |thread| is not given, create a new one and own it. |
+ m_owningThread = adoptPtr(Platform::current()->createThread(name)); |
+ m_thread = m_owningThread.get(); |
+ } |
} |
WebThreadSupportingGC::~WebThreadSupportingGC() |
@@ -29,24 +42,28 @@ WebThreadSupportingGC::~WebThreadSupportingGC() |
if (ThreadState::current()) { |
haraken
2015/09/01 09:32:37
if (ThreadState::current() && m_owningThread)
It
kinuko
2015/09/01 09:48:56
Done.
|
// WebThread's destructor blocks until all the tasks are processed. |
SafePointScope scope(ThreadState::HeapPointersOnStack); |
- m_thread.clear(); |
+ m_owningThread.clear(); |
} |
} |
void WebThreadSupportingGC::initialize() |
{ |
m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
- platformThread().addTaskObserver(m_pendingGCRunner.get()); |
+ m_thread->addTaskObserver(m_pendingGCRunner.get()); |
ThreadState::attach(); |
- OwnPtr<MessageLoopInterruptor> interruptor = adoptPtr(new MessageLoopInterruptor(&platformThread())); |
+ OwnPtr<MessageLoopInterruptor> interruptor = adoptPtr(new MessageLoopInterruptor(m_thread)); |
ThreadState::current()->addInterruptor(interruptor.release()); |
} |
void WebThreadSupportingGC::shutdown() |
{ |
// Ensure no posted tasks will run from this point on. |
- platformThread().removeTaskObserver(m_pendingGCRunner.get()); |
- platformThread().scheduler()->shutdown(); |
+ m_thread->removeTaskObserver(m_pendingGCRunner.get()); |
+ |
+ // Shutdown the thread (via its scheduler) only when the thread is created |
+ // and is owned by this instance. |
+ if (m_owningThread) |
+ m_owningThread->scheduler()->shutdown(); |
ThreadState::detach(); |
m_pendingGCRunner = nullptr; |