+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.
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;
};
--- /dev/null
+#include <JavaScriptCore/HashMap.h>
--- /dev/null
+#include <JavaScriptCore/HashSet.h>
--- /dev/null
+#include <JavaScriptCore/Vector.h>
/*
- * 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
/*
- * 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
" 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);
// 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;
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);
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);
}
}