USE(WEB_THREAD): More explicit WebThread initialization
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Sep 2013 01:49:50 +0000 (01:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Sep 2013 01:49:50 +0000 (01:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121454

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2013-09-16
Reviewed by Benjamin Poulain.

Be more explicit when initializing WebThread only data.

* wtf/MainThread.h:
* wtf/MainThread.cpp:
(WTF::initializeWebThreadOnce):
(WTF::initializeWebThread):
Ensure one time initialization.

* wtf/mac/MainThreadMac.mm:
(WTF::initializeMainThreadPlatform):
(WTF::initializeWebThreadPlatform):
Move WebThread value initialization to its own function.

(WTF::isMainThread):
Remove no longer invalid assert if WebThread was not initialized.

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

Source/WTF/ChangeLog
Source/WTF/wtf/MainThread.cpp
Source/WTF/wtf/MainThread.h
Source/WTF/wtf/mac/MainThreadMac.mm

index db1342a..911a3e5 100644 (file)
@@ -1,3 +1,26 @@
+2013-09-16  Joseph Pecoraro  <pecoraro@apple.com>
+
+        USE(WEB_THREAD): More explicit WebThread initialization
+        https://bugs.webkit.org/show_bug.cgi?id=121454
+
+        Reviewed by Benjamin Poulain.
+
+        Be more explicit when initializing WebThread only data.
+
+        * wtf/MainThread.h:
+        * wtf/MainThread.cpp:
+        (WTF::initializeWebThreadOnce):
+        (WTF::initializeWebThread):
+        Ensure one time initialization.
+
+        * wtf/mac/MainThreadMac.mm:
+        (WTF::initializeMainThreadPlatform):
+        (WTF::initializeWebThreadPlatform):
+        Move WebThread value initialization to its own function.
+
+        (WTF::isMainThread):
+        Remove no longer invalid assert if WebThread was not initialized.
+
 2013-09-16  Benjamin Poulain  <benjamin@webkit.org>
 
         Fix WebKit1 build after r155910
index e77b15f..d16f95a 100644 (file)
@@ -127,6 +127,18 @@ void initializeMainThreadToProcessMainThread()
 {
     pthread_once(&initializeMainThreadKeyOnce, initializeMainThreadToProcessMainThreadOnce);
 }
+#else
+static pthread_once_t initializeWebThreadKeyOnce = PTHREAD_ONCE_INIT;
+
+static void initializeWebThreadOnce()
+{
+    initializeWebThreadPlatform();
+}
+
+void initializeWebThread()
+{
+    pthread_once(&initializeWebThreadKeyOnce, initializeWebThreadOnce);
+}
 #endif // !USE(WEB_THREAD)
 
 #endif
index e4aa159..3c726fa 100644 (file)
@@ -54,9 +54,11 @@ WTF_EXPORT_PRIVATE bool isMainThread();
 #if USE(WEB_THREAD)
 WTF_EXPORT_PRIVATE bool isWebThread();
 WTF_EXPORT_PRIVATE bool isUIThread();
+WTF_EXPORT_PRIVATE bool initializeWebThread();
 WTF_EXPORT_PRIVATE void initializeApplicationUIThreadIdentifier();
 WTF_EXPORT_PRIVATE void initializeWebThreadIdentifier();
 WTF_EXPORT_PRIVATE bool canAccessThreadLocalDataForThread(ThreadIdentifier);
+void initializeWebThreadPlatform();
 #else
 inline bool isWebThread() { return isMainThread(); }
 inline bool isUIThread() { return isMainThread(); }
@@ -97,6 +99,7 @@ using WTF::setMainThreadCallbacksPaused;
 using WTF::isMainThread;
 using WTF::isMainThreadOrGCThread;
 #if USE(WEB_THREAD)
+using WTF::initializeWebThread;
 using WTF::initializeApplicationUIThreadIdentifier;
 using WTF::initializeWebThreadIdentifier;
 using WTF::canAccessThreadLocalDataForThread;
index cc3fee9..857c704 100644 (file)
@@ -73,9 +73,15 @@ void initializeMainThreadPlatform()
     staticMainThreadCaller = [[JSWTFMainThreadCaller alloc] init];
 
     mainThreadEstablishedAsPthreadMain = false;
+
+#if !USE(WEB_THREAD)
     mainThreadPthread = pthread_self();
     mainThreadNSThread = [[NSThread currentThread] retain];
-    
+#else
+    ASSERT(!mainThreadPthread);
+    ASSERT(!mainThreadNSThread);
+#endif
+
     initializeGCThreads();
 }
 
@@ -136,7 +142,6 @@ void scheduleDispatchFunctionsOnMainThread()
 #if USE(WEB_THREAD)
 bool isMainThread()
 {
-    ASSERT(!mainThreadEstablishedAsPthreadMain);
     return (isWebThread() || pthread_main_np()) && WebCoreWebThreadIsLockedOrDisabled();
 }
 
@@ -162,6 +167,15 @@ void initializeWebThreadIdentifier()
     sWebThreadIdentifier = currentThread();
 }
 
+void initializeWebThreadPlatform()
+{
+    ASSERT(!pthread_main_np());
+
+    mainThreadEstablishedAsPthreadMain = false;
+    mainThreadPthread = pthread_self();
+    mainThreadNSThread = [[NSThread currentThread] retain];
+}
+
 bool canAccessThreadLocalDataForThread(ThreadIdentifier threadId)
 {
     ThreadIdentifier currentThreadId = currentThread();