<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[149843] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/149843">149843</a></dd>
<dt>Author</dt> <dd>paroga@webkit.org</dd>
<dt>Date</dt> <dd>2013-05-09 14:35:01 -0700 (Thu, 09 May 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>[DRT] Replace JavaScriptThreadingPthreads.cpp with JavaScriptThreading.cpp
https://bugs.webkit.org/show_bug.cgi?id=92505

Reviewed by Brent Fulgham.

* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/JavaScriptThreading.cpp: Copied from DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp.
(javaScriptThreadsMutex):
(javaScriptThreads):
(runJavaScriptThread):
(startJavaScriptThreads):
(stopJavaScriptThreads):
* DumpRenderTree/pthreads: Removed.
* DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Removed.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreeDumpRenderTreexcodeprojprojectpbxproj">trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsDumpRenderTreeJavaScriptThreadingcpp">trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkToolsDumpRenderTreepthreadsJavaScriptThreadingPthreadscpp">trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (149842 => 149843)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2013-05-09 21:34:45 UTC (rev 149842)
+++ trunk/Tools/ChangeLog        2013-05-09 21:35:01 UTC (rev 149843)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2013-05-09  Patrick Gansterer  &lt;paroga@webkit.org&gt;
+
+        [DRT] Replace JavaScriptThreadingPthreads.cpp with JavaScriptThreading.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=92505
+
+        Reviewed by Brent Fulgham.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/JavaScriptThreading.cpp: Copied from DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp.
+        (javaScriptThreadsMutex):
+        (javaScriptThreads):
+        (runJavaScriptThread):
+        (startJavaScriptThreads):
+        (stopJavaScriptThreads):
+        * DumpRenderTree/pthreads: Removed.
+        * DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Removed.
+
</ins><span class="cx"> 2013-05-09  Mario Sanchez Prada  &lt;mario.prada@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Update Simon Pena email on his behalf.
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeDumpRenderTreexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj (149842 => 149843)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj        2013-05-09 21:34:45 UTC (rev 149842)
+++ trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj        2013-05-09 21:35:01 UTC (rev 149843)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx">                 29CFBA10122736E600BC30C0 /* AccessibilityTextMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */; };
</span><span class="cx">                 29CFBA11122736E600BC30C0 /* AccessibilityTextMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CFBA0F122736E600BC30C0 /* AccessibilityTextMarker.cpp */; };
</span><span class="cx">                 29CFBA2E12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */; };
</span><ins>+                2CE88FA217124D8C00734FC0 /* JavaScriptThreading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CE88FA117124CEE00734FC0 /* JavaScriptThreading.cpp */; };
</ins><span class="cx">                 2D403F05150871F9005358D2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE8257EF08D22389000507AB /* Carbon.framework */; };
</span><span class="cx">                 2D403F06150871F9005358D2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A84F608908B136DA00E9745F /* Cocoa.framework */; };
</span><span class="cx">                 2D403F08150871F9005358D2 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23BCB88F0EA57623003C6289 /* OpenGL.framework */; };
</span><span class="lines">@@ -122,7 +123,6 @@
</span><span class="cx">                 BC0E26150E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC0E26140E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm */; };
</span><span class="cx">                 BC0E26150E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm */; };
</span><span class="cx">                 BC47412A0D038A4C0072B006 /* JavaScriptThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4741290D038A4C0072B006 /* JavaScriptThreading.h */; };
</span><del>-                BC4741410D038A570072B006 /* JavaScriptThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */; };
</del><span class="cx">                 BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */; };
</span><span class="cx">                 BC9D90250C97472E0099A4A3 /* WorkQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9D90220C97472E0099A4A3 /* WorkQueue.h */; };
</span><span class="cx">                 BC9D90260C97472E0099A4A3 /* WorkQueueItem.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9D90230C97472E0099A4A3 /* WorkQueueItem.h */; };
</span><span class="lines">@@ -273,6 +273,7 @@
</span><span class="cx">                 29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityTextMarker.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 29CFBA0F122736E600BC30C0 /* AccessibilityTextMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityTextMarker.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityTextMarkerMac.mm; path = mac/AccessibilityTextMarkerMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2CE88FA117124CEE00734FC0 /* JavaScriptThreading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptThreading.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2D403EA215087142005358D2 /* LayoutTestHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayoutTestHelper.m; path = mac/LayoutTestHelper.m; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2D403F19150871F9005358D2 /* LayoutTestHelper */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.executable&quot;; includeInIndex = 0; path = LayoutTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">                 31117B3A15D9A56A00163BC8 /* MockWebNotificationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MockWebNotificationProvider.h; path = mac/MockWebNotificationProvider.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -336,7 +337,6 @@
</span><span class="cx">                 BC0E26140E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityUIElementMac.mm; path = mac/AccessibilityUIElementMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityCommonMac.mm; path = mac/AccessibilityCommonMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 BC4741290D038A4C0072B006 /* JavaScriptThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptThreading.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaScriptThreadingPthreads.cpp; path = pthreads/JavaScriptThreadingPthreads.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><span class="cx">                 BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 BC9D90220C97472E0099A4A3 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 BC9D90230C97472E0099A4A3 /* WorkQueueItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WorkQueueItem.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -456,12 +456,12 @@
</span><span class="cx">                                 A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */,
</span><span class="cx">                                 A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */,
</span><span class="cx">                                 BC4741290D038A4C0072B006 /* JavaScriptThreading.h */,
</span><del>-                                BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */,
</del><span class="cx">                                 BCA18C0A0C9B59EF00114369 /* DumpRenderTreeMac.h */,
</span><span class="cx">                                 BCA18B730C9B08F100114369 /* DumpRenderTreeDraggingInfo.h */,
</span><span class="cx">                                 BCA18B740C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm */,
</span><span class="cx">                                 A8D79CE80FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.h */,
</span><span class="cx">                                 A8D79CE90FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m */,
</span><ins>+                                2CE88FA117124CEE00734FC0 /* JavaScriptThreading.cpp */,
</ins><span class="cx">                                 44A997820FCDE86400580F10 /* WebArchiveDumpSupport.h */,
</span><span class="cx">                                 44A997830FCDE86400580F10 /* WebArchiveDumpSupport.cpp */,
</span><span class="cx">                                 440590701268453800CFD48D /* WebArchiveDumpSupportMac.mm */,
</span><span class="lines">@@ -985,7 +985,7 @@
</span><span class="cx">                                 BCA18B230C9B014B00114369 /* GCControllerMac.mm in Sources */,
</span><span class="cx">                                 AA5A15EF16E15CD000F7C561 /* AccessibilityControllerIOS.mm in Sources */,
</span><span class="cx">                                 5185F6B210714E07007AA393 /* HistoryDelegate.mm in Sources */,
</span><del>-                                BC4741410D038A570072B006 /* JavaScriptThreadingPthreads.cpp in Sources */,
</del><ins>+                                2CE88FA217124D8C00734FC0 /* JavaScriptThreading.cpp in Sources */,
</ins><span class="cx">                                 E1B7816511AF31B7007E1BC2 /* MockGeolocationProvider.mm in Sources */,
</span><span class="cx">                                 31117B3D15D9A56A00163BC8 /* MockWebNotificationProvider.mm in Sources */,
</span><span class="cx">                                 BCA18B720C9B08DB00114369 /* NavigationController.m in Sources */,
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeJavaScriptThreadingcppfromrev149820trunkToolsDumpRenderTreepthreadsJavaScriptThreadingPthreadscpp"></a>
<div class="copfile"><h4>Copied: trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp (from rev 149820, trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp) (0 => 149843)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp                                (rev 0)
+++ trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp        2013-05-09 21:35:01 UTC (rev 149843)
</span><span class="lines">@@ -0,0 +1,151 @@
</span><ins>+/*
+ * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
+ *           (C) 2007 Eric Seidel &lt;eric@webkit.org&gt;
+ *           (C) 2012 Patrick Ganstere &lt;paroga@paroga.com&gt;
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. (&quot;Apple&quot;) nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

+#include &quot;config.h&quot;
+#include &quot;JavaScriptThreading.h&quot;
+
+#include &lt;JavaScriptCore/JavaScriptCore.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;wtf/Assertions.h&gt;
+#include &lt;wtf/HashSet.h&gt;
+#include &lt;wtf/Vector.h&gt;
+
+static const size_t javaScriptThreadsCount = 4;
+static bool javaScriptThreadsShouldTerminate;
+static JSContextGroupRef javaScriptThreadsGroup;
+
+static Mutex&amp; javaScriptThreadsMutex()
+{
+    DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
+    return staticMutex;
+}
+
+typedef HashSet&lt;ThreadIdentifier&gt; ThreadSet;
+static ThreadSet&amp; javaScriptThreads()
+{
+    DEFINE_STATIC_LOCAL(ThreadSet, staticJavaScriptThreads, ());
+    ASSERT(!javaScriptThreadsMutex().tryLock());
+    return staticJavaScriptThreads;
+}
+
+// This function exercises JSC in a loop until javaScriptThreadsShouldTerminate
+// becomes true or it probabilistically decides to spawn a replacement thread and exit.
+void runJavaScriptThread(void*)
+{
+    static const char* const script =
+        &quot;var array = [];&quot;
+        &quot;for (var i = 0; i &lt; 1024; i++) {&quot;
+        &quot;    array.push(String(i));&quot;
+        &quot;}&quot;;
+
+    JSGlobalContextRef ctx;
+    {
+        MutexLocker locker(javaScriptThreadsMutex());
+        ctx = JSGlobalContextCreateInGroup(javaScriptThreadsGroup, 0);
+    }
+
+    JSStringRef scriptRef;
+    {
+        MutexLocker locker(javaScriptThreadsMutex());
+        scriptRef = JSStringCreateWithUTF8CString(script);
+    }
+
+    while (true) {
+        {
+            MutexLocker locker(javaScriptThreadsMutex());
+            JSValueRef exception = 0;
+            JSEvaluateScript(ctx, scriptRef, 0, 0, 1, &amp;exception);
+            ASSERT(!exception);
+        }
+
+        {
+            MutexLocker locker(javaScriptThreadsMutex());
+            const size_t valuesCount = 1024;
+            JSValueRef values[valuesCount];
+            for (size_t i = 0; i &lt; valuesCount; ++i)
+                values[i] = JSObjectMake(ctx, 0, 0);
+        }
+
+        {
+            MutexLocker locker(javaScriptThreadsMutex());
+            if (javaScriptThreadsShouldTerminate)
+                break;
+        }
+
+        // Respawn probabilistically.
+        if (rand() % 5)
+            continue;
+
+        MutexLocker locker(javaScriptThreadsMutex());
+        ThreadIdentifier thread = currentThread();
+        detachThread(thread);
+        javaScriptThreads().remove(thread);
+        javaScriptThreads().add(createThread(&amp;runJavaScriptThread, 0, 0));
+        break;
+    }
+
+    MutexLocker locker(javaScriptThreadsMutex());
+    JSStringRelease(scriptRef);
+    JSGarbageCollect(ctx);
+    JSGlobalContextRelease(ctx);
+}
+
+void startJavaScriptThreads()
+{
+    javaScriptThreadsGroup = JSContextGroupCreate();
+
+    MutexLocker locker(javaScriptThreadsMutex());
+
+    for (size_t i = 0; i &lt; javaScriptThreadsCount; ++i)
+        javaScriptThreads().add(createThread(&amp;runJavaScriptThread, 0, 0));
+}
+
+void stopJavaScriptThreads()
+{
+    {
+        MutexLocker locker(javaScriptThreadsMutex());
+        javaScriptThreadsShouldTerminate = true;
+    }
+
+    Vector&lt;ThreadIdentifier, javaScriptThreadsCount&gt; threads;
+    {
+        MutexLocker locker(javaScriptThreadsMutex());
+        copyToVector(javaScriptThreads(), threads);
+        ASSERT(threads.size() == javaScriptThreadsCount);
+    }
+
+    for (size_t i = 0; i &lt; javaScriptThreadsCount; ++i)
+        waitForThreadCompletion(threads[i]);
+
+    javaScriptThreads().clear();
+
+    JSContextGroupRelease(javaScriptThreadsGroup);
+}
</ins></span></pre></div>
<a id="trunkToolsDumpRenderTreepthreadsJavaScriptThreadingPthreadscpp"></a>
<div class="delfile"><h4>Deleted: trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp (149842 => 149843)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp        2013-05-09 21:34:45 UTC (rev 149842)
+++ trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp        2013-05-09 21:35:01 UTC (rev 149843)
</span><span class="lines">@@ -1,148 +0,0 @@
</span><del>-/*
- * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
- *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
- *           (C) 2007 Eric Seidel &lt;eric@webkit.org&gt;
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer. 
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution. 
- * 3.  Neither the name of Apple Computer, Inc. (&quot;Apple&quot;) nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission. 
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */

-#include &quot;config.h&quot;
-#include &quot;JavaScriptThreading.h&quot;
-
-#include &lt;CoreFoundation/CoreFoundation.h&gt;
-#include &lt;JavaScriptCore/JavaScriptCore.h&gt;
-#include &lt;pthread.h&gt;
-#include &lt;wtf/Assertions.h&gt;
-#include &lt;wtf/HashSet.h&gt;
-
-static JSContextGroupRef javaScriptThreadsGroup;
-
-static pthread_mutex_t javaScriptThreadsMutex = PTHREAD_MUTEX_INITIALIZER;
-static bool javaScriptThreadsShouldTerminate;
-
-static const int javaScriptThreadsCount = 4;
-
-typedef HashSet&lt;pthread_t&gt; ThreadSet;
-
-static ThreadSet* javaScriptThreads()
-{
-    ASSERT(pthread_mutex_trylock(&amp;javaScriptThreadsMutex) == EBUSY);
-    static ThreadSet staticJavaScriptThreads;
-    return &amp;staticJavaScriptThreads;
-}
-
-// This function exercises JSC in a loop until javaScriptThreadsShouldTerminate
-// becomes true or it probabilistically decides to spawn a replacement thread and exit.
-void* runJavaScriptThread(void* arg)
-{
-    static const char* const script =
-        &quot;var array = [];&quot;
-        &quot;for (var i = 0; i &lt; 1024; i++) {&quot;
-        &quot;    array.push(String(i));&quot;
-        &quot;}&quot;;
-
-    pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-    JSGlobalContextRef ctx = JSGlobalContextCreateInGroup(javaScriptThreadsGroup, 0);
-    pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-    pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-    JSStringRef scriptRef = JSStringCreateWithUTF8CString(script);
-    pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-    while (1) {
-        pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-        JSValueRef exception = 0;
-        JSEvaluateScript(ctx, scriptRef, 0, 0, 1, &amp;exception);
-        ASSERT(!exception);
-        pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-        pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-        size_t valuesCount = 1024;
-        JSValueRef values[valuesCount];
-        for (size_t i = 0; i &lt; valuesCount; ++i)
-            values[i] = JSObjectMake(ctx, 0, 0);
-        pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-        // Check for cancellation.
-        if (javaScriptThreadsShouldTerminate)
-            goto done;
-
-        // Respawn probabilistically.
-        if (random() % 5 == 0) {
-            pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-            pthread_t pthread;
-            pthread_create(&amp;pthread, 0, &amp;runJavaScriptThread, 0);
-            pthread_detach(pthread);
-            javaScriptThreads()-&gt;add(pthread);
-            pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-            goto done;
-        }
-    }
-
-done:
-    pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-    JSStringRelease(scriptRef);
-    JSGarbageCollect(ctx);
-    JSGlobalContextRelease(ctx);
-    javaScriptThreads()-&gt;remove(pthread_self());
-    pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-    return 0;
-}
-
-void startJavaScriptThreads()
-{
-    javaScriptThreadsGroup = JSContextGroupCreate();
-
-    pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-
-    for (int i = 0; i &lt; javaScriptThreadsCount; i++) {
-        pthread_t pthread;
-        pthread_create(&amp;pthread, 0, &amp;runJavaScriptThread, 0);
-        pthread_detach(pthread);
-        javaScriptThreads()-&gt;add(pthread);
-    }
-
-    pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-}
-
-void stopJavaScriptThreads()
-{
-    pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-
-    javaScriptThreadsShouldTerminate = true;
-
-    pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-    while (true) {
-        pthread_mutex_lock(&amp;javaScriptThreadsMutex);
-        int threadCount = javaScriptThreads()-&gt;size();
-        pthread_mutex_unlock(&amp;javaScriptThreadsMutex);
-
-        if (!threadCount)
-            break;
-
-        usleep(1000);
-    }
-}
</del></span></pre>
</div>
</div>

</body>
</html>