Regression(r248533) Assertion hit in isMainThread() for some clients using WTF becaus...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Aug 2019 20:31:08 +0000 (20:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Aug 2019 20:31:08 +0000 (20:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201083

Reviewed by Alex Christensen.

An assertion is hit in isMainThread() for some clients using WTF because the main thread is not initialized, since r248533.
Clients can work around this by calling WTF::initializeMainThread() before using WTF but it seems unfortunate to force them
to do so. I propose we disable the assertion until the main thread is initialized.

* wtf/MainThread.h:
* wtf/RefCounted.h:
(WTF::RefCountedBase::RefCountedBase):
(WTF::RefCountedBase::applyRefDerefThreadingCheck const):
* wtf/cocoa/MainThreadCocoa.mm:
(WTF::isMainThreadInitialized):
* wtf/generic/MainThreadGeneric.cpp:
(WTF::isMainThreadInitialized):

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

Source/WTF/ChangeLog
Source/WTF/wtf/MainThread.h
Source/WTF/wtf/RefCounted.h
Source/WTF/wtf/cocoa/MainThreadCocoa.mm
Source/WTF/wtf/generic/MainThreadGeneric.cpp

index bd4241b..0970271 100644 (file)
@@ -1,3 +1,23 @@
+2019-08-23  Chris Dumez  <cdumez@apple.com>
+
+        Regression(r248533) Assertion hit in isMainThread() for some clients using WTF because the main thread is not initialized
+        https://bugs.webkit.org/show_bug.cgi?id=201083
+
+        Reviewed by Alex Christensen.
+
+        An assertion is hit in isMainThread() for some clients using WTF because the main thread is not initialized, since r248533.
+        Clients can work around this by calling WTF::initializeMainThread() before using WTF but it seems unfortunate to force them
+        to do so. I propose we disable the assertion until the main thread is initialized.
+
+        * wtf/MainThread.h:
+        * wtf/RefCounted.h:
+        (WTF::RefCountedBase::RefCountedBase):
+        (WTF::RefCountedBase::applyRefDerefThreadingCheck const):
+        * wtf/cocoa/MainThreadCocoa.mm:
+        (WTF::isMainThreadInitialized):
+        * wtf/generic/MainThreadGeneric.cpp:
+        (WTF::isMainThreadInitialized):
+
 2019-08-21  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthn] Support NFC authenticators for iOS
index 12bfae4..785aefb 100644 (file)
@@ -54,6 +54,7 @@ WTF_EXPORT_PRIVATE void setMainThreadCallbacksPaused(bool paused);
 
 WTF_EXPORT_PRIVATE bool isMainThread();
 WTF_EXPORT_PRIVATE bool isMainThreadIfInitialized();
+WTF_EXPORT_PRIVATE bool isMainThreadInitialized();
 
 WTF_EXPORT_PRIVATE bool canAccessThreadLocalDataForThread(Thread&);
 
index 9bcf5eb..1333387 100644 (file)
@@ -91,7 +91,8 @@ protected:
     RefCountedBase()
         : m_refCount(1)
 #if !ASSERT_DISABLED
-        , m_isOwnedByMainThread(isMainThread())
+        , m_isOwnedByMainThread(isMainThreadIfInitialized())
+        , m_areThreadingChecksEnabled(isMainThreadInitialized())
 #endif
 #if CHECK_REF_COUNTED_LIFECYCLE
         , m_deletionHasBegun(false)
@@ -105,7 +106,7 @@ protected:
 #if !ASSERT_DISABLED
         if (hasOneRef()) {
             // Likely an ownership transfer across threads that may be safe.
-            m_isOwnedByMainThread = isMainThread();
+            m_isOwnedByMainThread = isMainThreadIfInitialized();
         } else if (areThreadingChecksEnabledGlobally && m_areThreadingChecksEnabled) {
             // If you hit this assertion, it means that the RefCounted object was ref/deref'd
             // from both the main thread and another in a way that is likely concurrent and unsafe.
index be7ea45..58b6f91 100644 (file)
@@ -181,6 +181,11 @@ bool isMainThreadIfInitialized()
     return isMainThread();
 }
 
+bool isMainThreadInitialized()
+{
+    return true;
+}
+
 bool isUIThread()
 {
     return pthread_main_np();
@@ -239,6 +244,11 @@ bool isMainThreadIfInitialized()
     return pthread_equal(pthread_self(), mainThreadPthread);
 }
 
+bool isMainThreadInitialized()
+{
+    return mainThreadEstablishedAsPthreadMain || mainThreadPthread;
+}
+
 #endif // USE(WEB_THREAD)
 
 } // namespace WTF
index a366101..fc31c80 100644 (file)
@@ -92,6 +92,11 @@ bool isMainThreadIfInitialized()
     return isMainThread();
 }
 
+bool isMainThreadInitialized()
+{
+    return true;
+}
+
 void scheduleDispatchFunctionsOnMainThread()
 {
     // Use a RunLoop::Timer instead of RunLoop::dispatch() to be able to use a different priority and