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

Unified Diff: Source/platform/WebThreadSupportingGC.cpp

Issue 1319363002: Makes WebThreadSupportingGC constructible for an existing thread (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: addressed comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/WebThreadSupportingGC.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/WebThreadSupportingGC.cpp
diff --git a/Source/platform/WebThreadSupportingGC.cpp b/Source/platform/WebThreadSupportingGC.cpp
index f2aec3e1addf011c63eaf4c1a887c67e01faa58e..151c2771748bbd699ec214c593a1d09776be9b97 100644
--- a/Source/platform/WebThreadSupportingGC.cpp
+++ b/Source/platform/WebThreadSupportingGC.cpp
@@ -13,40 +13,57 @@ namespace blink {
PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name)
{
-#if ENABLE(ASSERT)
- WTF::willCreateThread();
-#endif
- return adoptPtr(new WebThreadSupportingGC(name));
+ return adoptPtr(new WebThreadSupportingGC(name, nullptr));
}
-WebThreadSupportingGC::WebThreadSupportingGC(const char* name)
- : m_thread(adoptPtr(Platform::current()->createThread(name)))
+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
+ 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()
{
- if (ThreadState::current()) {
+ if (ThreadState::current() && m_owningThread) {
// 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;
« no previous file with comments | « Source/platform/WebThreadSupportingGC.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698