]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/mac/MainThreadMac.mm
JavaScriptCore-576.tar.gz
[apple/javascriptcore.git] / wtf / mac / MainThreadMac.mm
index b04ef0e427b0058f3e6f05e2da01f358132829a0..0ddd5f64ea28a0726792c9ebabf8385c0f8250b5 100644 (file)
@@ -30,6 +30,7 @@
 #import "MainThread.h"
 
 #import <Foundation/NSThread.h>
+#import <wtf/Assertions.h>
 
 @interface WTFMainThreadCaller : NSObject {
 }
 
 namespace WTF {
 
+static WTFMainThreadCaller* staticMainThreadCaller = nil;
+#if USE(WEB_THREAD)
+static NSThread* webThread = nil;
+#endif
+
+void initializeMainThreadPlatform()
+{
+    ASSERT(!staticMainThreadCaller);
+    staticMainThreadCaller = [[WTFMainThreadCaller alloc] init];
+
+#if USE(WEB_THREAD)
+    webThread = [[NSThread currentThread] retain];
+#endif
+}
+
 void scheduleDispatchFunctionsOnMainThread()
 {
-    WTFMainThreadCaller *caller = [[WTFMainThreadCaller alloc] init];
-    [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
-    [caller release];
+    ASSERT(staticMainThreadCaller);
+#if USE(WEB_THREAD)
+    [staticMainThreadCaller performSelector:@selector(call) onThread:webThread withObject:nil waitUntilDone:NO];
+#else
+    [staticMainThreadCaller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
+#endif
 }
 
 } // namespace WTF