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

Unified Diff: Source/platform/WebThreadSupportingGC.cpp

Issue 857193004: [NOT READY FOR REVIEW YET]workers: Some refactoring to allow creating new kind of worker threads Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 11 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 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());
« 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