Source/WebCore/ChangeLog

112013-01-16 Adam Barth <abarth@webkit.org>
22
 3 Introduce HTMLParserThread to be able to parse on a background thread
 4 https://bugs.webkit.org/show_bug.cgi?id=107070
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch introduces a simple thread class that we can use to parse
 9 HTML. This patch is unlikely to be the final design because we'll
 10 likely want to use libdispatch or some other platform-specific thread
 11 pool. However, this implementation is enough to let us work on the
 12 parser-specific aspects of this feature.
 13
 14 * CMakeLists.txt:
 15 * GNUmakefile.list.am:
 16 * Target.pri:
 17 * WebCore.gypi:
 18 * WebCore.vcproj/WebCore.vcproj:
 19 * WebCore.xcodeproj/project.pbxproj:
 20 * html/parser/HTMLParserThread.cpp: Added.
 21 (WebCore):
 22 (WebCore::HTMLParserThread::HTMLParserThread):
 23 (WebCore::HTMLParserThread::~HTMLParserThread):
 24 (WebCore::HTMLParserThread::start):
 25 (WebCore::HTMLParserThread::stop):
 26 (WebCore::HTMLParserThread::shared):
 27 (WebCore::HTMLParserThread::postTask):
 28 (WebCore::HTMLParserThread::threadStart):
 29 (WebCore::HTMLParserThread::runLoop):
 30 * html/parser/HTMLParserThread.h: Added.
 31 (WebCore):
 32 (HTMLParserThread):
 33 (WebCore::HTMLParserThread::create):
 34 (WebCore::HTMLParserThread::threadId):
 35
 362013-01-16 Adam Barth <abarth@webkit.org>
 37
338 Teach HTMLParserOptions about Settings::threadedHTMLParser
439 https://bugs.webkit.org/show_bug.cgi?id=107068
540

Source/WebCore/CMakeLists.txt

@@set(WebCore_SOURCES
15351535 html/parser/HTMLParserIdioms.cpp
15361536 html/parser/HTMLParserOptions.cpp
15371537 html/parser/HTMLParserScheduler.cpp
 1538 html/parser/HTMLParserThread.cpp
15381539 html/parser/HTMLFormattingElementList.cpp
15391540 html/parser/HTMLMetaCharsetParser.cpp
15401541 html/parser/HTMLPreloadScanner.cpp

Source/WebCore/GNUmakefile.list.am

@@webcore_sources += \
35543554 Source/WebCore/html/parser/HTMLParserOptions.h \
35553555 Source/WebCore/html/parser/HTMLParserScheduler.cpp \
35563556 Source/WebCore/html/parser/HTMLParserScheduler.h \
 3557 Source/WebCore/html/parser/HTMLParserThread.cpp \
 3558 Source/WebCore/html/parser/HTMLParserThread.h \
35573559 Source/WebCore/html/parser/HTMLPreloadScanner.cpp \
35583560 Source/WebCore/html/parser/HTMLPreloadScanner.h \
35593561 Source/WebCore/html/parser/HTMLScriptRunner.cpp \

Source/WebCore/Target.pri

@@SOURCES += \
718718 html/parser/HTMLParserIdioms.cpp \
719719 html/parser/HTMLParserOptions.cpp \
720720 html/parser/HTMLParserScheduler.cpp \
 721 html/parser/HTMLParserThread.cpp \
721722 html/parser/HTMLPreloadScanner.cpp \
722723 html/parser/HTMLScriptRunner.cpp \
723724 html/parser/HTMLSourceTracker.cpp \

Source/WebCore/WebCore.gypi

33563356 'html/parser/HTMLParserOptions.h',
33573357 'html/parser/HTMLParserScheduler.cpp',
33583358 'html/parser/HTMLParserScheduler.h',
 3359 'html/parser/HTMLParserThread.cpp',
 3360 'html/parser/HTMLParserThread.h',
33593361 'html/parser/HTMLPreloadScanner.cpp',
33603362 'html/parser/HTMLPreloadScanner.h',
33613363 'html/parser/HTMLScriptRunner.cpp',

Source/WebCore/WebCore.vcproj/WebCore.vcproj

6462964629 >
6463064630 </File>
6463164631 <File
 64632 RelativePath="..\html\parser\HTMLParserThread.cpp"
 64633 >
 64634 </File>
 64635 <File
 64636 RelativePath="..\html\parser\HTMLParserThread.h"
 64637 >
 64638 </File>
 64639 <File
6463264640 RelativePath="..\html\parser\HTMLPreloadScanner.cpp"
6463364641 >
6463464642 </File>

Source/WebCore/WebCore.xcodeproj/project.pbxproj

36573657 978D07CA145A10160096908D /* SVGException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 978D07C9145A10160096908D /* SVGException.cpp */; };
36583658 978D07CC145A102E0096908D /* XPathException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 978D07CB145A102E0096908D /* XPathException.cpp */; };
36593659 978D07CE145A10370096908D /* XMLHttpRequestException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 978D07CD145A10370096908D /* XMLHttpRequestException.cpp */; };
 3660 979AA9E816A78AE7007329FA /* HTMLParserThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 979AA9E516A78ADB007329FA /* HTMLParserThread.cpp */; };
 3661 979AA9E916A78AEE007329FA /* HTMLParserThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 979AA9E616A78ADB007329FA /* HTMLParserThread.h */; };
36603662 979F43D31075E44A0000F83B /* NavigationScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 979F43D11075E44A0000F83B /* NavigationScheduler.cpp */; };
36613663 979F43D41075E44A0000F83B /* NavigationScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 979F43D21075E44A0000F83B /* NavigationScheduler.h */; settings = {ATTRIBUTES = (Private, ); }; };
36623664 97AA3CA5145237CC003E1DA6 /* EventTargetHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 97AA3CA3145237CC003E1DA6 /* EventTargetHeaders.h */; };

1103311035 978D07C9145A10160096908D /* SVGException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGException.cpp; sourceTree = "<group>"; };
1103411036 978D07CB145A102E0096908D /* XPathException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XPathException.cpp; sourceTree = "<group>"; };
1103511037 978D07CD145A10370096908D /* XMLHttpRequestException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLHttpRequestException.cpp; sourceTree = "<group>"; };
 11038 979AA9E516A78ADB007329FA /* HTMLParserThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HTMLParserThread.cpp; path = parser/HTMLParserThread.cpp; sourceTree = "<group>"; };
 11039 979AA9E616A78ADB007329FA /* HTMLParserThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLParserThread.h; path = parser/HTMLParserThread.h; sourceTree = "<group>"; };
1103611040 979F43D11075E44A0000F83B /* NavigationScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavigationScheduler.cpp; sourceTree = "<group>"; };
1103711041 979F43D21075E44A0000F83B /* NavigationScheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationScheduler.h; sourceTree = "<group>"; };
1103811042 97AA3CA3145237CC003E1DA6 /* EventTargetHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventTargetHeaders.h; sourceTree = "<group>"; };

1408314087 FC63BDB2167AABAC00F9380F /* CSSSupportsRule.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CSSSupportsRule.idl; sourceTree = "<group>"; };
1408414088 FC84802D167AB444008CD100 /* JSCSSSupportsRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSSupportsRule.cpp; sourceTree = "<group>"; };
1408514089 FC84802E167AB444008CD100 /* JSCSSSupportsRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSSupportsRule.h; sourceTree = "<group>"; };
14086  FCD8832816A49F8200962227 /* DOMCSSSupportsRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DOMCSSSupportsRule.h; path = DOMCSSSupportsRule.h; sourceTree = "<group>"; };
14087  FCD8832916A49F8200962227 /* DOMCSSSupportsRule.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DOMCSSSupportsRule.mm; path = DOMCSSSupportsRule.mm; sourceTree = "<group>"; };
14088  FCEBBAAA16A4967A00FA20A6 /* DOMCSSSupportsRuleInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DOMCSSSupportsRuleInternal.h; path = DOMCSSSupportsRuleInternal.h; sourceTree = "<group>"; };
 14090 FCD8832816A49F8200962227 /* DOMCSSSupportsRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMCSSSupportsRule.h; sourceTree = "<group>"; };
 14091 FCD8832916A49F8200962227 /* DOMCSSSupportsRule.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMCSSSupportsRule.mm; sourceTree = "<group>"; };
 14092 FCEBBAAA16A4967A00FA20A6 /* DOMCSSSupportsRuleInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMCSSSupportsRuleInternal.h; sourceTree = "<group>"; };
1408914093 FCEBCD711623A7910029965E /* CSSGrammar.y.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; path = CSSGrammar.y.in; sourceTree = "<group>"; };
1409014094 FCEBCD721623A7910029965E /* CSSGrammar.y.includes */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; path = CSSGrammar.y.includes; sourceTree = "<group>"; };
1409114095 FD00D7A214A3F61900734011 /* SincResampler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SincResampler.cpp; sourceTree = "<group>"; };

1473414738 A9D247F90D757E4100FDF959 /* Plugins */,
1473514739 89F60B17157F6A020075E157 /* Quota */,
1473614740 BC9854460CD3DA5F00069BC1 /* Ranges */,
 14741 AA7FEE9B16A491A1004C0C33 /* Speech */,
1473714742 A83B79150CCB0078000B0825 /* Storage */,
1473814743 A83B790A0CCAFF47000B0825 /* SVG */,
1473914744 417DA71213735D90007C57FB /* Testing */,
1474014745 E1C8BE4B0E8BD0D10064CB7D /* Threads */,
1474114746 BC9854530CD3DA8F00069BC1 /* Traversal */,
14742  AA7FEE9B16A491A1004C0C33 /* Speech */,
1474314747 FDA15E7B12B03E04003A583A /* WebAudio */,
1474414748 5DA5E0F9102B950400088CF9 /* WebSockets */,
1474514749 BC9854430CD3D9D000069BC1 /* Window */,

1621816222 BCE1C41A0D982980003B02F2 /* Location.cpp */,
1621916223 BCE1C4190D982980003B02F2 /* Location.h */,
1622016224 BCE1C4220D9829F2003B02F2 /* Location.idl */,
 16225 BC59DEFA169DEDD80016AC34 /* make_settings.pl */,
1622116226 931BCC601124DFCB00BE70DD /* MediaCanStartListener.h */,
1622216227 9FFE3E7811B59C5D0037874E /* MemoryInfo.cpp */,
1622316228 9FFE3E7911B59C5D0037874E /* MemoryInfo.h */,

1627916284 14C9A5E90B3D105F005A0232 /* Settings.cpp */,
1628016285 F587863A02DE3A1401EA4122 /* Settings.h */,
1628116286 BC59DEF8169DEDC30016AC34 /* Settings.in */,
16282  BC59DEFA169DEDD80016AC34 /* make_settings.pl */,
1628316287 626CDE0C1140424C001E5A68 /* SpatialNavigation.cpp */,
1628416288 626CDE0D1140424C001E5A68 /* SpatialNavigation.h */,
1628516289 7578F90811DDF26900D933C5 /* SpeechInput.cpp */,

1855018554 973F4188169B95EF0006BF60 /* HTMLParserOptions.h */,
1855118555 977B3857122883E900B81FF8 /* HTMLParserScheduler.cpp */,
1855218556 977B3858122883E900B81FF8 /* HTMLParserScheduler.h */,
 18557 979AA9E516A78ADB007329FA /* HTMLParserThread.cpp */,
 18558 979AA9E616A78ADB007329FA /* HTMLParserThread.h */,
1855318559 977B3859122883E900B81FF8 /* HTMLPreloadScanner.cpp */,
1855418560 977B385A122883E900B81FF8 /* HTMLPreloadScanner.h */,
1855518561 977B385B122883E900B81FF8 /* HTMLScriptRunner.cpp */,

1855918565 977E2DCC12F0E28300C13379 /* HTMLSourceTracker.h */,
1856018566 97C1F552122855CB00EDE615 /* HTMLStackItem.h */,
1856118567 97C1F552122855CB00EDE616 /* HTMLToken.h */,
18562  97C1F552122855CB00EDE617 /* HTMLTokenTypes.h */,
1856318568 977B385E122883E900B81FF8 /* HTMLTokenizer.cpp */,
1856418569 977B385F122883E900B81FF8 /* HTMLTokenizer.h */,
 18570 97C1F552122855CB00EDE617 /* HTMLTokenTypes.h */,
1856518571 977B37211228721700B81FF8 /* HTMLTreeBuilder.cpp */,
1856618572 977B37221228721700B81FF8 /* HTMLTreeBuilder.h */,
1856718573 977B3860122883E900B81FF8 /* HTMLViewSourceParser.cpp */,

2165021656 BC53C6910DA591140021EB5D /* CSSGradientValue.h */,
2165121657 FCEBCD711623A7910029965E /* CSSGrammar.y.in */,
2165221658 FCEBCD721623A7910029965E /* CSSGrammar.y.includes */,
21653  FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */,
2165421659 FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */,
 21660 FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */,
2165521661 BC772B360C4EA91E0083285F /* CSSHelper.h */,
2165621662 BC23E76B0DAE88A9009FDC91 /* CSSImageGeneratorValue.cpp */,
2165721663 BC23EE910DAED2BC009FDC91 /* CSSImageGeneratorValue.h */,

2391023916 9712A5AE15004EDA0048AF10 /* DOMWindowIndexedDatabase.h in Headers */,
2391123917 97B38E27151C4271004622E9 /* DOMWindowNotifications.h in Headers */,
2391223918 97D2AD0414B823A60093DF32 /* DOMWindowProperty.h in Headers */,
23913  AA2A5AD616A4861600975A25 /* DOMWindowSpeechSynthesis.h in Headers */,
2391423919 89F60B11157F686E0075E157 /* DOMWindowQuota.h in Headers */,
 23920 AA2A5AD616A4861600975A25 /* DOMWindowSpeechSynthesis.h in Headers */,
2391523921 A8CCBB49151F831600AB7CE9 /* DOMWindowWebDatabase.h in Headers */,
2391623922 BC53DA2E1143121E000D817E /* DOMWrapperWorld.h in Headers */,
2391723923 1A1D13800A5325520064BF5F /* DOMXPath.h in Headers */,

2424824254 973F418A169B95FF0006BF60 /* HTMLParserOptions.h in Headers */,
2424924255 449B19F50FA72ECE0015CA4A /* HTMLParserQuirks.h in Headers */,
2425024256 977B3871122883E900B81FF8 /* HTMLParserScheduler.h in Headers */,
 24257 979AA9E916A78AEE007329FA /* HTMLParserThread.h in Headers */,
2425124258 A871D4560A127CBC00B12A68 /* HTMLPlugInElement.h in Headers */,
2425224259 4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */,
2425324260 A8EA7CB00A192B9C00A8EF5F /* HTMLPreElement.h in Headers */,

2545125458 514C76790CE923A1007EF3CD /* ResourceHandle.h in Headers */,
2545225459 514C767A0CE923A1007EF3CD /* ResourceHandleClient.h in Headers */,
2545325460 514C767B0CE923A1007EF3CD /* ResourceHandleInternal.h in Headers */,
 25461 51E4143416A6596300C633C7 /* ResourceHandleTypes.h in Headers */,
2545425462 656D373F0ADBA5DE00A4554D /* ResourceLoader.h in Headers */,
2545525463 D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
2545625464 492863991253B8FC00F792D6 /* ResourceLoadInfo.h in Headers */,

2622926237 E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
2623026238 977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
2623126239 FD537353137B651800008DCE /* ZeroPole.h in Headers */,
26232  51E4143416A6596300C633C7 /* ResourceHandleTypes.h in Headers */,
2623326240 );
2623426241 runOnlyForDeploymentPostprocessing = 0;
2623526242 };

2679326800 BC02A6460E09AAE9004B6D2B /* CSSFunctionValue.cpp in Sources */,
2679426801 BC23E4E10DAACE0F009FDC91 /* CSSGradientValue.cpp in Sources */,
2679526802 650F53DD09D15DDF00C9B0C8 /* CSSGrammar.cpp in Sources */,
 26803 FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */,
2679626804 BC23E76C0DAE88A9009FDC91 /* CSSImageGeneratorValue.cpp in Sources */,
2679726805 9393E5FF151A99F200066F06 /* CSSImageSetValue.cpp in Sources */,
2679826806 A80E6CFE0A1989CA007FB8C5 /* CSSImageValue.cpp in Sources */,

2752127529 93E2A306123E9DC0009FE12A /* HTMLParserIdioms.cpp in Sources */,
2752227530 973F418B169B96030006BF60 /* HTMLParserOptions.cpp in Sources */,
2752327531 977B3870122883E900B81FF8 /* HTMLParserScheduler.cpp in Sources */,
 27532 979AA9E816A78AE7007329FA /* HTMLParserThread.cpp in Sources */,
2752427533 A871D4570A127CBC00B12A68 /* HTMLPlugInElement.cpp in Sources */,
2752527534 4415292F0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp in Sources */,
2752627535 A8EA7CAD0A192B9C00A8EF5F /* HTMLPreElement.cpp in Sources */,

2937629385 E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
2937729386 977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
2937829387 FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
29379  FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */,
2938029388 );
2938129389 runOnlyForDeploymentPostprocessing = 0;
2938229390 };

Source/WebCore/html/parser/HTMLParserThread.cpp

 1/*
 2 * Copyright (C) 2013 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions are
 6 * met:
 7 *
 8 * * Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * * Redistributions in binary form must reproduce the above
 11 * copyright notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * * Neither the name of Google Inc. nor the names of its
 15 * contributors may be used to endorse or promote products derived from
 16 * this software without specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 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.
 29 */
 30
 31#include "config.h"
 32
 33#if ENABLE(THREADED_HTML_PARSER)
 34
 35#include "HTMLParserThread.h"
 36
 37namespace WebCore {
 38
 39HTMLParserThread::HTMLParserThread()
 40 : m_threadID(0)
 41{
 42}
 43
 44HTMLParserThread::~HTMLParserThread()
 45{
 46 ASSERT(m_queue.killed());
 47}
 48
 49bool HTMLParserThread::start()
 50{
 51 MutexLocker lock(m_threadCreationMutex);
 52 if (m_threadID)
 53 return true;
 54 m_threadID = createThread(HTMLParserThread::threadStart, this, "WebCore: HTMLParser");
 55 return m_threadID;
 56}
 57
 58void HTMLParserThread::stop()
 59{
 60 m_queue.kill();
 61 waitForThreadCompletion(m_threadID);
 62}
 63
 64HTMLParserThread* HTMLParserThread::shared()
 65{
 66 static HTMLParserThread* thread;
 67 if (!thread) {
 68 thread = HTMLParserThread::create().leakPtr();
 69 thread->start();
 70 }
 71 return thread;
 72}
 73
 74void HTMLParserThread::postTask(const Closure& function)
 75{
 76 m_queue.append(adoptPtr(new Closure(function)));
 77}
 78
 79void HTMLParserThread::threadStart(void* arg)
 80{
 81 HTMLParserThread* thread = static_cast<HTMLParserThread*>(arg);
 82 thread->runLoop();
 83}
 84
 85void HTMLParserThread::runLoop()
 86{
 87 {
 88 // Wait for HTMLParserThread::start() to complete to have m_threadID
 89 // established before starting the main loop.
 90 MutexLocker lock(m_threadCreationMutex);
 91 }
 92 while (OwnPtr<Closure> function = m_queue.waitForMessage())
 93 (*function)();
 94
 95 // stop() will wait to join the thread, so we do not detach here.
 96}
 97
 98} // namespace WebCore
 99
 100#endif // ENABLE(BLOB)

Source/WebCore/html/parser/HTMLParserThread.h

 1/*
 2 * Copyright (C) 2013 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions are
 6 * met:
 7 *
 8 * * Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * * Redistributions in binary form must reproduce the above
 11 * copyright notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * * Neither the name of Google Inc. nor the names of its
 15 * contributors may be used to endorse or promote products derived from
 16 * this software without specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 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.
 29 */
 30
 31#ifndef HTMLParserThread_h
 32#define HTMLParserThread_h
 33
 34#if ENABLE(THREADED_HTML_PARSER)
 35
 36#include <stdio.h>
 37#include <wtf/Functional.h>
 38#include <wtf/MessageQueue.h>
 39#include <wtf/PassOwnPtr.h>
 40#include <wtf/PassRefPtr.h>
 41#include <wtf/Threading.h>
 42
 43namespace WebCore {
 44
 45// FIXME:: Closure is the Chromium-name for Function<void()>, but we may want something else for WebCore.
 46typedef Function<void()> Closure;
 47
 48class HTMLParserThread {
 49public:
 50 static PassOwnPtr<HTMLParserThread> create()
 51 {
 52 return adoptPtr(new HTMLParserThread());
 53 }
 54 ~HTMLParserThread();
 55
 56 static HTMLParserThread* shared();
 57
 58 bool start();
 59 void stop();
 60
 61 void postTask(const Closure&);
 62
 63 ThreadIdentifier threadId() const { return m_threadID; }
 64
 65private:
 66 HTMLParserThread();
 67
 68 static void threadStart(void*);
 69 void runLoop();
 70
 71 Mutex m_threadCreationMutex;
 72 MessageQueue<Closure> m_queue;
 73 ThreadIdentifier m_threadID;
 74};
 75
 76} // namespace WebCore
 77
 78#endif // ENABLE(THREADED_HTML_PARSER)
 79
 80#endif // HTMLParserThread_h