| OLD | NEW |
| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/html/parser/HTMLParserThread.h" | 32 #include "core/html/parser/HTMLParserThread.h" |
| 33 | 33 |
| 34 #include "platform/Task.h" | 34 #include "platform/Task.h" |
| 35 #include "platform/TaskSynchronizer.h" | |
| 36 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 37 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 38 | 37 |
| 39 namespace WebCore { | 38 namespace WebCore { |
| 40 | 39 |
| 41 static HTMLParserThread* s_sharedThread = 0; | 40 static HTMLParserThread* s_sharedThread = 0; |
| 42 | 41 |
| 43 HTMLParserThread::HTMLParserThread() | 42 HTMLParserThread::HTMLParserThread() |
| 44 { | 43 { |
| 45 } | 44 } |
| 46 | 45 |
| 47 HTMLParserThread::~HTMLParserThread() | 46 HTMLParserThread::~HTMLParserThread() |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void HTMLParserThread::init() | 50 void HTMLParserThread::init() |
| 52 { | 51 { |
| 53 ASSERT(!s_sharedThread); | 52 ASSERT(!s_sharedThread); |
| 54 s_sharedThread = new HTMLParserThread; | 53 s_sharedThread = new HTMLParserThread; |
| 55 } | 54 } |
| 56 | 55 |
| 57 void HTMLParserThread::setupHTMLParserThread() | |
| 58 { | |
| 59 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | |
| 60 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(&platformThre
ad())); | |
| 61 platformThread().addTaskObserver(m_pendingGCRunner.get()); | |
| 62 ThreadState::attach(); | |
| 63 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); | |
| 64 } | |
| 65 | |
| 66 void HTMLParserThread::shutdown() | 56 void HTMLParserThread::shutdown() |
| 67 { | 57 { |
| 68 ASSERT(s_sharedThread); | 58 ASSERT(s_sharedThread); |
| 69 TaskSynchronizer taskSynchronizer; | |
| 70 s_sharedThread->postTask(WTF::bind(&HTMLParserThread::cleanupHTMLParserThrea
d, s_sharedThread, &taskSynchronizer)); | |
| 71 taskSynchronizer.waitForTaskCompletion(); | |
| 72 delete s_sharedThread; | 59 delete s_sharedThread; |
| 73 s_sharedThread = 0; | 60 s_sharedThread = 0; |
| 74 } | 61 } |
| 75 | 62 |
| 76 void HTMLParserThread::cleanupHTMLParserThread(TaskSynchronizer* taskSynchronize
r) | |
| 77 { | |
| 78 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); | |
| 79 ThreadState::detach(); | |
| 80 platformThread().removeTaskObserver(m_pendingGCRunner.get()); | |
| 81 taskSynchronizer->taskCompleted(); | |
| 82 m_pendingGCRunner = nullptr; | |
| 83 m_messageLoopInterruptor = nullptr; | |
| 84 } | |
| 85 | |
| 86 HTMLParserThread* HTMLParserThread::shared() | 63 HTMLParserThread* HTMLParserThread::shared() |
| 87 { | 64 { |
| 88 return s_sharedThread; | 65 return s_sharedThread; |
| 89 } | 66 } |
| 90 | 67 |
| 91 blink::WebThread& HTMLParserThread::platformThread() | 68 blink::WebThread& HTMLParserThread::platformThread() |
| 92 { | 69 { |
| 93 if (!m_thread) { | 70 if (!m_thread) |
| 94 m_thread = adoptPtr(blink::Platform::current()->createThread("HTMLParser
Thread")); | 71 m_thread = adoptPtr(blink::Platform::current()->createThread("HTMLParser
Thread")); |
| 95 postTask(WTF::bind(&HTMLParserThread::setupHTMLParserThread, this)); | |
| 96 } | |
| 97 return *m_thread; | 72 return *m_thread; |
| 98 } | 73 } |
| 99 | 74 |
| 100 void HTMLParserThread::postTask(const Closure& closure) | 75 void HTMLParserThread::postTask(const Closure& closure) |
| 101 { | 76 { |
| 102 platformThread().postTask(new Task(closure)); | 77 platformThread().postTask(new Task(closure)); |
| 103 } | 78 } |
| 104 | 79 |
| 105 } // namespace WebCore | 80 } // namespace WebCore |
| OLD | NEW |