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.
5 #ifndef WebThreadSupportingGC_h
6 #define WebThreadSupportingGC_h
8 #include "platform/heap/glue/MessageLoopInterruptor.h"
9 #include "platform/heap/glue/PendingGCRunner.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebTaskRunner.h"
12 #include "public/platform/WebThread.h"
13 #include "wtf/Noncopyable.h"
14 #include "wtf/OwnPtr.h"
15 #include "wtf/PassOwnPtr.h"
19 // WebThreadSupportingGC wraps a WebThread and adds support for attaching
20 // to and detaching from the Blink GC infrastructure. The initialize method
21 // must be called during initialization on the WebThread and before the
22 // thread allocates any objects managed by the Blink GC. The shutdown
23 // method must be called on the WebThread during shutdown when the thread
24 // no longer needs to access objects managed by the Blink GC.
26 // WebThreadSupportingGC usually internally creates and owns WebThread unless
27 // an existing WebThread is given via createForThread.
28 class PLATFORM_EXPORT WebThreadSupportingGC final
{
29 WTF_MAKE_NONCOPYABLE(WebThreadSupportingGC
);
31 static PassOwnPtr
<WebThreadSupportingGC
> create(const char* name
);
32 static PassOwnPtr
<WebThreadSupportingGC
> createForThread(WebThread
*);
33 ~WebThreadSupportingGC();
35 void postTask(const WebTraceLocation
& location
, WebTaskRunner::Task
* task
)
37 m_thread
->taskRunner()->postTask(location
, task
);
40 void postDelayedTask(const WebTraceLocation
& location
, WebTaskRunner::Task
* task
, long long delayMs
)
42 m_thread
->taskRunner()->postDelayedTask(location
, task
, delayMs
);
45 bool isCurrentThread() const
47 return m_thread
->isCurrentThread();
50 void addTaskObserver(WebThread::TaskObserver
* observer
)
52 m_thread
->addTaskObserver(observer
);
55 void removeTaskObserver(WebThread::TaskObserver
* observer
)
57 m_thread
->removeTaskObserver(observer
);
63 WebThread
& platformThread() const
70 WebThreadSupportingGC(const char* name
, WebThread
*);
72 OwnPtr
<PendingGCRunner
> m_pendingGCRunner
;
74 // m_thread is guaranteed to be non-null after this instance is constructed.
75 // m_owningThread is non-null unless this instance is constructed for an
76 // existing thread via createForThread().
77 WebThread
* m_thread
= nullptr;
78 OwnPtr
<WebThread
> m_owningThread
;