Commit 20699b2c authored by haraken@chromium.org's avatar haraken@chromium.org

Oilpan: Support the HTML parser thread in oilpan

After r170314, the HTML parser thread allocates on-heap objects such as CSSValues. So this CL supports the HTML parser thread in oilpan. Also this CL marks the CSSValue hierarchy with ThreadAffinity=AnyThread because CSSValue can be allocated by both main thread and parser threads.

BUG=340522

Review URL: https://codereview.chromium.org/216203006

git-svn-id: svn://svn.chromium.org/blink/trunk@170564 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 59ea4848
......@@ -32,6 +32,7 @@
#include "core/html/parser/HTMLParserThread.h"
#include "platform/Task.h"
#include "platform/TaskSynchronizer.h"
#include "public/platform/Platform.h"
#include "wtf/PassOwnPtr.h"
......@@ -53,13 +54,35 @@ void HTMLParserThread::init()
s_sharedThread = new HTMLParserThread;
}
void HTMLParserThread::setupHTMLParserThread()
{
m_pendingGCRunner = adoptPtr(new PendingGCRunner);
m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThread()));
platformThread().addTaskObserver(m_pendingGCRunner.get());
ThreadState::attach();
ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get());
}
void HTMLParserThread::shutdown()
{
ASSERT(s_sharedThread);
TaskSynchronizer taskSynchronizer;
s_sharedThread->postTask(WTF::bind(&HTMLParserThread::cleanupHTMLParserThread, s_sharedThread, &taskSynchronizer));
taskSynchronizer.waitForTaskCompletion();
delete s_sharedThread;
s_sharedThread = 0;
}
void HTMLParserThread::cleanupHTMLParserThread(TaskSynchronizer* taskSynchronizer)
{
ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get());
ThreadState::detach();
platformThread().removeTaskObserver(m_pendingGCRunner.get());
taskSynchronizer->taskCompleted();
m_pendingGCRunner = nullptr;
m_messageLoopInterruptor = nullptr;
}
HTMLParserThread* HTMLParserThread::shared()
{
return s_sharedThread;
......@@ -67,8 +90,10 @@ HTMLParserThread* HTMLParserThread::shared()
blink::WebThread& HTMLParserThread::platformThread()
{
if (!m_thread)
if (!m_thread) {
m_thread = adoptPtr(blink::Platform::current()->createThread("HTMLParserThread"));
postTask(WTF::bind(&HTMLParserThread::setupHTMLParserThread, this));
}
return *m_thread;
}
......
......@@ -31,12 +31,16 @@
#ifndef HTMLParserThread_h
#define HTMLParserThread_h
#include "heap/glue/MessageLoopInterruptor.h"
#include "heap/glue/PendingGCRunner.h"
#include "public/platform/WebThread.h"
#include "wtf/Functional.h"
#include "wtf/OwnPtr.h"
#include "public/platform/WebThread.h"
namespace WebCore {
class TaskSynchronizer;
class HTMLParserThread {
public:
static void init();
......@@ -51,8 +55,12 @@ public:
private:
HTMLParserThread();
~HTMLParserThread();
void setupHTMLParserThread();
void cleanupHTMLParserThread(TaskSynchronizer*);
OwnPtr<blink::WebThread> m_thread;
OwnPtr<PendingGCRunner> m_pendingGCRunner;
OwnPtr<MessageLoopInterruptor> m_messageLoopInterruptor;
};
} // namespace WebCore
......
......@@ -80,7 +80,7 @@ enum ThreadAffinity {
class Node;
class CSSValue;
template<typename T, bool derivesNodeOrCSSValue = WTF::IsSubclass<T, Node>::value || WTF::IsSubclass<T, CSSValue>::value > struct DefaultThreadingTrait;
template<typename T, bool derivesNode = WTF::IsSubclass<T, Node>::value> struct DefaultThreadingTrait;
template<typename T>
struct DefaultThreadingTrait<T, false> {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment