Index: Source/platform/WebThreadSupportingGC.cpp |
diff --git a/Source/platform/WebThreadSupportingGC.cpp b/Source/platform/WebThreadSupportingGC.cpp |
index df76335a69473b83aed6c4e6dd002bd3b9652250..e2ea27ddf183add2a2821e4e72841d6c3de1f5b3 100644 |
--- a/Source/platform/WebThreadSupportingGC.cpp |
+++ b/Source/platform/WebThreadSupportingGC.cpp |
@@ -7,17 +7,34 @@ |
namespace blink { |
-PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name) |
-{ |
- return adoptPtr(new WebThreadSupportingGC(name)); |
-} |
+namespace { |
+ |
+class OwnWebThreadSupportingGC final : public WebThreadSupportingGC { |
+ WTF_MAKE_NONCOPYABLE(OwnWebThreadSupportingGC); |
+public: |
+ explicit OwnWebThreadSupportingGC(const char* name); |
+ ~OwnWebThreadSupportingGC() override; |
-WebThreadSupportingGC::WebThreadSupportingGC(const char* name) |
+private: |
+ WebThread& platformThread() const override |
+ { |
+ ASSERT(m_thread); |
+ return *m_thread; |
+ } |
+ // FIXME: This has to be last because of crbug.com/401397. |
+ // A WorkerThread might get deleted before it had a chance to properly |
+ // shut down. By deleting the WebThread first, we can guarantee that |
+ // no pending tasks on the thread might want to access any of the other |
+ // members during the WorkerThread's destruction. |
+ OwnPtr<WebThread> m_thread; |
+}; |
+ |
+OwnWebThreadSupportingGC::OwnWebThreadSupportingGC(const char* name) |
: m_thread(adoptPtr(Platform::current()->createThread(name))) |
{ |
} |
-WebThreadSupportingGC::~WebThreadSupportingGC() |
+OwnWebThreadSupportingGC::~OwnWebThreadSupportingGC() |
{ |
if (ThreadState::current()) { |
// WebThread's destructor blocks until all the tasks are processed. |
@@ -26,8 +43,20 @@ WebThreadSupportingGC::~WebThreadSupportingGC() |
} |
} |
+} // namespace |
+ |
+PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name) |
+{ |
+ return adoptPtr(new OwnWebThreadSupportingGC(name)); |
+} |
+ |
+WebThreadSupportingGC::~WebThreadSupportingGC() |
+{ |
+} |
+ |
void WebThreadSupportingGC::attachGC() |
{ |
+ ASSERT(platformThread().isCurrentThread()); |
m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThread())); |
platformThread().addTaskObserver(m_pendingGCRunner.get()); |
@@ -37,6 +66,7 @@ void WebThreadSupportingGC::attachGC() |
void WebThreadSupportingGC::detachGC() |
{ |
+ ASSERT(platformThread().isCurrentThread()); |
ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); |
ThreadState::detach(); |
platformThread().removeTaskObserver(m_pendingGCRunner.get()); |