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

Side by Side Diff: Source/core/html/parser/HTMLParserThread.cpp

Issue 469683002: Implement WebThreadSupportingGC, which wraps a WebThread attached to Oilpan's GC (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 void HTMLParserThread::init() 51 void HTMLParserThread::init()
52 { 52 {
53 ASSERT(!s_sharedThread); 53 ASSERT(!s_sharedThread);
54 s_sharedThread = new HTMLParserThread; 54 s_sharedThread = new HTMLParserThread;
55 } 55 }
56 56
57 void HTMLParserThread::setupHTMLParserThread() 57 void HTMLParserThread::setupHTMLParserThread()
58 { 58 {
59 m_pendingGCRunner = adoptPtr(new PendingGCRunner); 59 ASSERT(m_thread);
60 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre ad())); 60 m_thread->attachGC();
61 platformThread().addTaskObserver(m_pendingGCRunner.get());
62 ThreadState::attach();
63 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get());
64 } 61 }
65 62
66 void HTMLParserThread::shutdown() 63 void HTMLParserThread::shutdown()
67 { 64 {
68 ASSERT(s_sharedThread); 65 ASSERT(s_sharedThread);
69 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 66 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
70 if (blink::Platform::current()->currentThread() && s_sharedThread->isRunning ()) { 67 if (blink::Platform::current()->currentThread() && s_sharedThread->isRunning ()) {
71 TaskSynchronizer taskSynchronizer; 68 TaskSynchronizer taskSynchronizer;
72 s_sharedThread->postTask(WTF::bind(&HTMLParserThread::cleanupHTMLParserT hread, s_sharedThread, &taskSynchronizer)); 69 s_sharedThread->postTask(WTF::bind(&HTMLParserThread::cleanupHTMLParserT hread, s_sharedThread, &taskSynchronizer));
73 taskSynchronizer.waitForTaskCompletion(); 70 taskSynchronizer.waitForTaskCompletion();
74 } 71 }
75 delete s_sharedThread; 72 delete s_sharedThread;
76 s_sharedThread = 0; 73 s_sharedThread = 0;
77 } 74 }
78 75
79 void HTMLParserThread::cleanupHTMLParserThread(TaskSynchronizer* taskSynchronize r) 76 void HTMLParserThread::cleanupHTMLParserThread(TaskSynchronizer* taskSynchronize r)
80 { 77 {
81 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); 78 m_thread->detachGC();
82 ThreadState::detach();
83 platformThread().removeTaskObserver(m_pendingGCRunner.get());
84 m_pendingGCRunner = nullptr;
85 m_messageLoopInterruptor = nullptr;
86 taskSynchronizer->taskCompleted(); 79 taskSynchronizer->taskCompleted();
87 } 80 }
88 81
89 HTMLParserThread* HTMLParserThread::shared() 82 HTMLParserThread* HTMLParserThread::shared()
90 { 83 {
91 return s_sharedThread; 84 return s_sharedThread;
92 } 85 }
93 86
94 blink::WebThread& HTMLParserThread::platformThread() 87 blink::WebThread& HTMLParserThread::platformThread()
95 { 88 {
96 if (!isRunning()) { 89 if (!isRunning()) {
97 m_thread = adoptPtr(blink::Platform::current()->createThread("HTMLParser Thread")); 90 m_thread = WebThreadRunner::create("HTMLParserThread");
98 postTask(WTF::bind(&HTMLParserThread::setupHTMLParserThread, this)); 91 postTask(WTF::bind(&HTMLParserThread::setupHTMLParserThread, this));
99 } 92 }
100 return *m_thread; 93 return m_thread->platformThread();
101 } 94 }
102 95
103 bool HTMLParserThread::isRunning() 96 bool HTMLParserThread::isRunning()
104 { 97 {
105 return !!m_thread; 98 return !!m_thread;
106 } 99 }
107 100
108 void HTMLParserThread::postTask(const Closure& closure) 101 void HTMLParserThread::postTask(const Closure& closure)
109 { 102 {
110 platformThread().postTask(new Task(closure)); 103 platformThread().postTask(new Task(closure));
111 } 104 }
112 105
113 } // namespace blink 106 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698