Move JavaScriptCore thread testing code to pthread specific directory
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2007 05:17:09 +0000 (05:17 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2007 05:17:09 +0000 (05:17 +0000)
        and remove the dependance on CoreFoundation by using WTF::HashSet.

        Reviewed by Geoff and Oliver.

        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
        * DumpRenderTree/ForwardingHeaders/wtf/HashMap.h: Added.
        * DumpRenderTree/ForwardingHeaders/wtf/HashSet.h: Added.
        * DumpRenderTree/ForwardingHeaders/wtf/Vector.h: Added.
        * DumpRenderTree/JavaScriptThreading.h: Copied from DumpRenderTree/mac/JavaScriptThreading.h.
        * DumpRenderTree/mac/JavaScriptThreading.cpp: Removed.
        * DumpRenderTree/mac/JavaScriptThreading.h: Removed.
        * DumpRenderTree/pthreads: Added.
        * DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Copied from DumpRenderTree/mac/JavaScriptThreading.cpp.
        (javaScriptThreads):
        (runJavaScriptThread):
        (startJavaScriptThreads):
        (stopJavaScriptThreads):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28377 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashMap.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashSet.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/Vector.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/JavaScriptThreading.h [moved from WebKitTools/DumpRenderTree/mac/JavaScriptThreading.h with 91% similarity]
WebKitTools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp [moved from WebKitTools/DumpRenderTree/mac/JavaScriptThreading.cpp with 68% similarity]

index 1a22183b4a4521763e16d79c4ba3df59177e0286..7b2b1e0440a980f168bb9bc10da5d3b9762899f7 100644 (file)
@@ -1,3 +1,24 @@
+2007-12-03  Sam Weinig  <sam@webkit.org>
+
+        Move JavaScriptCore thread testing code to pthread specific directory
+        and remove the dependance on CoreFoundation by using WTF::HashSet.
+
+        Reviewed by Geoff and Oliver.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/ForwardingHeaders/wtf/HashMap.h: Added.
+        * DumpRenderTree/ForwardingHeaders/wtf/HashSet.h: Added.
+        * DumpRenderTree/ForwardingHeaders/wtf/Vector.h: Added.
+        * DumpRenderTree/JavaScriptThreading.h: Copied from DumpRenderTree/mac/JavaScriptThreading.h.
+        * DumpRenderTree/mac/JavaScriptThreading.cpp: Removed.
+        * DumpRenderTree/mac/JavaScriptThreading.h: Removed.
+        * DumpRenderTree/pthreads: Added.
+        * DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Copied from DumpRenderTree/mac/JavaScriptThreading.cpp.
+        (javaScriptThreads):
+        (runJavaScriptThread):
+        (startJavaScriptThreads):
+        (stopJavaScriptThreads):
+
 2007-12-03  Andrew Bonventre  <andybons@google.com>
 
         Reviewed by Darin Adler.
index e34d5e44aa8768a82ec3efa245f940ee44d1d532..d451ffee303d58b3a781cc9ecd02b8da790b0392 100644 (file)
                A8B91ADC0CF3B32F008F91FF /* DumpRenderTreeWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = A8B91AD90CF3B32F008F91FF /* DumpRenderTreeWindow.mm */; };
                A8B91AE00CF3B372008F91FF /* DumpRenderTreeWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = A8B91ADD0CF3B372008F91FF /* DumpRenderTreeWindow.h */; };
                A8B91AE20CF3B372008F91FF /* DumpRenderTreePasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = A8B91ADF0CF3B372008F91FF /* DumpRenderTreePasteboard.h */; };
-               A8B91BFB0CF522B4008F91FF /* JavaScriptThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = A8B91BF50CF522B4008F91FF /* JavaScriptThreading.h */; };
                A8B91BFD0CF522B4008F91FF /* CheckedMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */; };
-               A8B91BFE0CF522B4008F91FF /* JavaScriptThreading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8B91BF80CF522B4008F91FF /* JavaScriptThreading.cpp */; };
                A8B91BFF0CF522B4008F91FF /* CheckedMalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */; };
                AE8259F308D22463000507AB /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE8257EF08D22389000507AB /* Carbon.framework */; };
                AE8259F408D22463000507AB /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE8257EF08D22389000507AB /* Carbon.framework */; };
                B5A752A208AF5D1F00138E45 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5A752A108AF5D1F00138E45 /* QuartzCore.framework */; };
                BC0131DA0C9772010087317D /* LayoutTestController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC0131D80C9772010087317D /* LayoutTestController.cpp */; };
                BC0131DB0C9772010087317D /* LayoutTestController.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0131D90C9772010087317D /* LayoutTestController.h */; };
+               BC47412A0D038A4C0072B006 /* JavaScriptThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4741290D038A4C0072B006 /* JavaScriptThreading.h */; };
+               BC4741410D038A570072B006 /* JavaScriptThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */; };
                BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */; };
                BC9D90250C97472E0099A4A3 /* WorkQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9D90220C97472E0099A4A3 /* WorkQueue.h */; };
                BC9D90260C97472E0099A4A3 /* WorkQueueItem.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9D90230C97472E0099A4A3 /* WorkQueueItem.h */; };
                A8B91AD90CF3B32F008F91FF /* DumpRenderTreeWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DumpRenderTreeWindow.mm; path = mac/DumpRenderTreeWindow.mm; sourceTree = "<group>"; };
                A8B91ADD0CF3B372008F91FF /* DumpRenderTreeWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DumpRenderTreeWindow.h; path = mac/DumpRenderTreeWindow.h; sourceTree = "<group>"; };
                A8B91ADF0CF3B372008F91FF /* DumpRenderTreePasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DumpRenderTreePasteboard.h; path = mac/DumpRenderTreePasteboard.h; sourceTree = "<group>"; };
-               A8B91BF50CF522B4008F91FF /* JavaScriptThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JavaScriptThreading.h; path = mac/JavaScriptThreading.h; sourceTree = "<group>"; };
                A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedMalloc.cpp; path = mac/CheckedMalloc.cpp; sourceTree = "<group>"; };
-               A8B91BF80CF522B4008F91FF /* JavaScriptThreading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaScriptThreading.cpp; path = mac/JavaScriptThreading.cpp; sourceTree = "<group>"; };
                A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CheckedMalloc.h; path = mac/CheckedMalloc.h; sourceTree = "<group>"; };
                AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */ = {isa = PBXFileReference; lastKnownFileType = file; name = "AHEM____.TTF"; path = "qt/fonts/AHEM____.TTF"; sourceTree = "<group>"; };
                AE8257EF08D22389000507AB /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
                B5A752A108AF5D1F00138E45 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = "<absolute>"; };
                BC0131D80C9772010087317D /* LayoutTestController.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = LayoutTestController.cpp; sourceTree = "<group>"; };
                BC0131D90C9772010087317D /* LayoutTestController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LayoutTestController.h; sourceTree = "<group>"; };
+               BC4741290D038A4C0072B006 /* JavaScriptThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptThreading.h; sourceTree = "<group>"; };
+               BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaScriptThreadingPthreads.cpp; path = pthreads/JavaScriptThreadingPthreads.cpp; sourceTree = "<group>"; };
                BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = WorkQueue.cpp; sourceTree = "<group>"; };
                BC9D90220C97472E0099A4A3 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = "<group>"; };
                BC9D90230C97472E0099A4A3 /* WorkQueueItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WorkQueueItem.h; sourceTree = "<group>"; };
                                BCA18C460C9B5B9400114369 /* DumpRenderTree.mm */,
                                A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */,
                                A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */,
-                               A8B91BF80CF522B4008F91FF /* JavaScriptThreading.cpp */,
-                               A8B91BF50CF522B4008F91FF /* JavaScriptThreading.h */,
+                               BC4741290D038A4C0072B006 /* JavaScriptThreading.h */,
+                               BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */,
                                BCA18C0A0C9B59EF00114369 /* DumpRenderTreeMac.h */,
                                BCA18B730C9B08F100114369 /* DumpRenderTreeDraggingInfo.h */,
                                BCA18B740C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm */,
                                BC9D90260C97472E0099A4A3 /* WorkQueueItem.h in Headers */,
                                A8B91AE00CF3B372008F91FF /* DumpRenderTreeWindow.h in Headers */,
                                A8B91AE20CF3B372008F91FF /* DumpRenderTreePasteboard.h in Headers */,
-                               A8B91BFB0CF522B4008F91FF /* JavaScriptThreading.h in Headers */,
                                A8B91BFF0CF522B4008F91FF /* CheckedMalloc.h in Headers */,
                                BCB284C70CFA83C4007E533E /* PixelDumpSupport.h in Headers */,
                                BCB284D00CFA83CC007E533E /* PixelDumpSupportCG.h in Headers */,
+                               BC47412A0D038A4C0072B006 /* JavaScriptThreading.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                A8B91ADA0CF3B32F008F91FF /* DumpRenderTreePasteboard.m in Sources */,
                                A8B91ADC0CF3B32F008F91FF /* DumpRenderTreeWindow.mm in Sources */,
                                A8B91BFD0CF522B4008F91FF /* CheckedMalloc.cpp in Sources */,
-                               A8B91BFE0CF522B4008F91FF /* JavaScriptThreading.cpp in Sources */,
                                BCB284CD0CFA83C8007E533E /* PixelDumpSupportCG.cpp in Sources */,
                                BCB284D60CFA83D1007E533E /* PixelDumpSupportMac.mm in Sources */,
+                               BC4741410D038A570072B006 /* JavaScriptThreadingPthreads.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashMap.h b/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashMap.h
new file mode 100644 (file)
index 0000000..9f262e2
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/HashMap.h>
diff --git a/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashSet.h b/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/HashSet.h
new file mode 100644 (file)
index 0000000..cfe2d80
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/HashSet.h>
diff --git a/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/Vector.h b/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/Vector.h
new file mode 100644 (file)
index 0000000..c6d15fd
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/Vector.h>
similarity index 91%
rename from WebKitTools/DumpRenderTree/mac/JavaScriptThreading.h
rename to WebKitTools/DumpRenderTree/JavaScriptThreading.h
index 57744dc75a072f56bfe4ab2ae7fec11ecb9dfd3c..43795a1a2f108d2060898034f6b2007b8ae3037e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007 Apple, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
  *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
  *           (C) 2007 Eric Seidel <eric@webkit.org>
  *
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef JavaScriptThreading_h
+#define JavaScriptThreading_h
+
 /* These functions start/stop threads used to abuse the JavaScript interpreter
  and assure that our JS implementation remains threadsafe */
 
 void startJavaScriptThreads();
 void stopJavaScriptThreads();
+
+#endif // JavaScriptThreading_h
similarity index 68%
rename from WebKitTools/DumpRenderTree/mac/JavaScriptThreading.cpp
rename to WebKitTools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp
index c382203dabe818b449d72d6c2236b04d66c24268..a305414a339a06996f385303ab4c9d23287524f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007 Apple, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
  *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
  *           (C) 2007 Eric Seidel <eric@webkit.org>
  *
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
-#import "JavaScriptThreading.h"
+#include "JavaScriptThreading.h"
 
-#import <CoreFoundation/CoreFoundation.h>
-#import <JavaScriptCore/JavaScriptCore.h>
-#import <pthread.h>
-#import <wtf/Assertions.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <JavaScriptCore/JavaScriptCore.h>
+#include <pthread.h>
+#include <wtf/Assertions.h>
+#include <wtf/HashSet.h>
 
 static pthread_mutex_t javaScriptThreadsMutex = PTHREAD_MUTEX_INITIALIZER;
 static bool javaScriptThreadsShouldTerminate;
 
 static const int javaScriptThreadsCount = 4;
-static CFMutableDictionaryRef javaScriptThreads()
+
+typedef HashSet<pthread_t> ThreadSet;
+
+static ThreadSet* javaScriptThreads()
 {
-    assert(pthread_mutex_trylock(&javaScriptThreadsMutex) == EBUSY);
-    static CFMutableDictionaryRef staticJavaScriptThreads;
-    if (!staticJavaScriptThreads)
-        staticJavaScriptThreads = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
-    return staticJavaScriptThreads;
+    ASSERT(pthread_mutex_trylock(&javaScriptThreadsMutex) == EBUSY);
+    static ThreadSet staticJavaScriptThreads;
+    return &staticJavaScriptThreads;
 }
 
 // Loops forever, running a script and randomly respawning, until 
@@ -58,14 +60,14 @@ void* runJavaScriptThread(void* arg)
         "    array.push(String(i));"
         "}";
 
-    while(1) {
-        JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
+    while (1) {
+        JSGlobalContextRef ctx = JSGlobalContextCreate(0);
         JSStringRef scriptRef = JSStringCreateWithUTF8CString(script);
 
-        JSValueRef exception = NULL;
-        JSEvaluateScript(ctx, scriptRef, NULL, NULL, 0, &exception);
-        assert(!exception);
-        
+        JSValueRef exception = 0;
+        JSEvaluateScript(ctx, scriptRef, 0, 0, 0, &exception);
+        ASSERT(!exception);
+
         JSGlobalContextRelease(ctx);
         JSStringRelease(scriptRef);
         
@@ -82,11 +84,11 @@ void* runJavaScriptThread(void* arg)
         // Respawn probabilistically.
         if (random() % 5 == 0) {
             pthread_t pthread;
-            pthread_create(&pthread, NULL, &runJavaScriptThread, NULL);
+            pthread_create(&pthread, 0, &runJavaScriptThread, 0);
             pthread_detach(pthread);
 
-            CFDictionaryRemoveValue(javaScriptThreads(), pthread_self());
-            CFDictionaryAddValue(javaScriptThreads(), pthread, NULL);
+            javaScriptThreads()->remove(pthread_self());
+            javaScriptThreads()->add(pthread);
 
             pthread_mutex_unlock(&javaScriptThreadsMutex);
             return 0;
@@ -102,9 +104,9 @@ void startJavaScriptThreads()
 
     for (int i = 0; i < javaScriptThreadsCount; i++) {
         pthread_t pthread;
-        pthread_create(&pthread, NULL, &runJavaScriptThread, NULL);
+        pthread_create(&pthread, 0, &runJavaScriptThread, 0);
         pthread_detach(pthread);
-        CFDictionaryAddValue(javaScriptThreads(), pthread, NULL);
+        javaScriptThreads()->add(pthread);
     }
 
     pthread_mutex_unlock(&javaScriptThreadsMutex);
@@ -116,15 +118,13 @@ void stopJavaScriptThreads()
 
     javaScriptThreadsShouldTerminate = true;
 
-    pthread_t* pthreads[javaScriptThreadsCount] = { 0 };
-    ASSERT(CFDictionaryGetCount(javaScriptThreads()) == javaScriptThreadsCount);
-    CFDictionaryGetKeysAndValues(javaScriptThreads(), (const void**)pthreads, 0);
+    ASSERT(javaScriptThreads()->size() == javaScriptThreadsCount);
 
     pthread_mutex_unlock(&javaScriptThreadsMutex);
 
-    for (int i = 0; i < javaScriptThreadsCount; i++) {
-        pthread_t* pthread = pthreads[i];
-        pthread_join(*pthread, 0);
-        free(pthread);
+    ThreadSet::iterator end = javaScriptThreads()->end();
+    for (ThreadSet::iterator it = javaScriptThreads()->begin(); it != end; ++it) {
+        pthread_t pthread = *it;
+        pthread_join(pthread, 0);
     }
 }