Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WebThreadSupportingGC_h | |
| 6 #define WebThreadSupportingGC_h | |
| 7 | |
| 8 #include "platform/heap/glue/MessageLoopInterruptor.h" | |
| 9 #include "platform/heap/glue/PendingGCRunner.h" | |
| 10 #include "public/platform/Platform.h" | |
| 11 #include "public/platform/WebThread.h" | |
| 12 #include "wtf/Noncopyable.h" | |
| 13 #include "wtf/OwnPtr.h" | |
| 14 #include "wtf/PassOwnPtr.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 // WebThreadSupportingGC wraps a WebThread and adds support for attaching | |
| 19 // to and detaching from the Blink GC infrastructure. The attachGC method | |
| 20 // must be called during initialization on the WebThread and before the | |
| 21 // thread allocates any objects managed by the Blink GC. The detach GC | |
| 22 // method must be called on the WebThread during shutdown when the thread | |
| 23 // no longer needs to access objects managed by the Blink GC. | |
| 24 class WebThreadSupportingGC { | |
| 25 WTF_MAKE_NONCOPYABLE(WebThreadSupportingGC); | |
| 26 public: | |
| 27 static PassOwnPtr<WebThreadSupportingGC> create(const char*); | |
| 28 | |
| 29 void postTask(WebThread::Task* task) | |
| 30 { | |
| 31 m_thread->postTask(task); | |
|
jochen (gone - plz use gerrit)
2014/08/13 12:35:42
this is not safe. on a worker thread, all posted t
Mads Ager (chromium)
2014/08/13 12:40:37
I'm not sure I understand. We are only replacing b
| |
| 32 } | |
| 33 | |
| 34 void postDelayedTask(WebThread::Task* task, long long delayMs) | |
| 35 { | |
| 36 m_thread->postDelayedTask(task, delayMs); | |
| 37 } | |
| 38 | |
| 39 bool isCurrentThread() const | |
| 40 { | |
| 41 return m_thread->isCurrentThread(); | |
| 42 } | |
| 43 | |
| 44 void addTaskObserver(WebThread::TaskObserver* observer) | |
| 45 { | |
| 46 m_thread->addTaskObserver(observer); | |
| 47 } | |
| 48 | |
| 49 void removeTaskObserver(WebThread::TaskObserver* observer) | |
| 50 { | |
| 51 m_thread->removeTaskObserver(observer); | |
| 52 } | |
| 53 | |
| 54 void enterRunLoop() | |
| 55 { | |
| 56 m_thread->enterRunLoop(); | |
| 57 } | |
| 58 | |
| 59 void exitRunLoop() | |
| 60 { | |
| 61 m_thread->exitRunLoop(); | |
| 62 } | |
| 63 | |
| 64 void attachGC(); | |
| 65 void detachGC(); | |
| 66 | |
| 67 WebThread& platformThread() const | |
| 68 { | |
| 69 ASSERT(m_thread); | |
| 70 return *m_thread; | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 explicit WebThreadSupportingGC(const char*); | |
| 75 | |
| 76 OwnPtr<PendingGCRunner> m_pendingGCRunner; | |
| 77 OwnPtr<MessageLoopInterruptor> m_messageLoopInterruptor; | |
| 78 | |
| 79 // FIXME: This has to be last because of crbug.com/401397. | |
| 80 // A WorkerThread might get deleted before it had a chance to properly | |
| 81 // shut down. By deleting the WebThread first, we can guarantee that | |
| 82 // no pending tasks on the thread might want to access any of the other | |
| 83 // members during the WorkerThread's destruction. | |
| 84 OwnPtr<WebThread> m_thread; | |
| 85 }; | |
| 86 | |
| 87 } | |
| 88 | |
| 89 #endif | |
| OLD | NEW |