Title: [225530] trunk/Source/WTF
Revision
225530
Author
[email protected]
Date
2017-12-05 12:34:06 -0800 (Tue, 05 Dec 2017)

Log Message

[WTF] Remove m_atomicStringTableDestructor in Thread by querying the condition at thread destruction
https://bugs.webkit.org/show_bug.cgi?id=180429

Reviewed by Alex Christensen.

We now have a pointer to the AtomicStringTable::destroy in Thread.
This pointer becomes nullptr only when the thread is the web thread not to destroy AtomicStringTable
twice in the UI thread and the web thread.

Instead of having a pointer in each Thread, we query whether the current thread is the web thread at
Thread destruction. And use this information to call AtomicStringTable::destroy. Then, we can drop
m_atomicStringTableDestructor field in Thread.

* wtf/Threading.cpp:
(WTF::Thread::didExit):
* wtf/Threading.h:
* wtf/mac/MainThreadMac.mm:
* wtf/text/AtomicStringTable.cpp:
(WTF::AtomicStringTable::create):
(WTF::AtomicStringTable::destroy):
* wtf/text/AtomicStringTable.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (225529 => 225530)


--- trunk/Source/WTF/ChangeLog	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/ChangeLog	2017-12-05 20:34:06 UTC (rev 225530)
@@ -1,3 +1,27 @@
+2017-12-05  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Remove m_atomicStringTableDestructor in Thread by querying the condition at thread destruction
+        https://bugs.webkit.org/show_bug.cgi?id=180429
+
+        Reviewed by Alex Christensen.
+
+        We now have a pointer to the AtomicStringTable::destroy in Thread.
+        This pointer becomes nullptr only when the thread is the web thread not to destroy AtomicStringTable
+        twice in the UI thread and the web thread.
+
+        Instead of having a pointer in each Thread, we query whether the current thread is the web thread at
+        Thread destruction. And use this information to call AtomicStringTable::destroy. Then, we can drop
+        m_atomicStringTableDestructor field in Thread.
+
+        * wtf/Threading.cpp:
+        (WTF::Thread::didExit):
+        * wtf/Threading.h:
+        * wtf/mac/MainThreadMac.mm:
+        * wtf/text/AtomicStringTable.cpp:
+        (WTF::AtomicStringTable::create):
+        (WTF::AtomicStringTable::destroy):
+        * wtf/text/AtomicStringTable.h:
+
 2017-12-01  Filip Pizlo  <[email protected]>
 
         GC constraint solving should be parallel

Modified: trunk/Source/WTF/wtf/Threading.cpp (225529 => 225530)


--- trunk/Source/WTF/wtf/Threading.cpp	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/wtf/Threading.cpp	2017-12-05 20:34:06 UTC (rev 225530)
@@ -197,9 +197,9 @@
             threadGroup->m_threads.remove(*this);
         }
     }
-    if (m_atomicStringTableDestructor)
-        m_atomicStringTableDestructor(m_defaultAtomicStringTable);
 
+    AtomicStringTable::destroy(m_defaultAtomicStringTable);
+
     // We would like to say "thread is exited" after unregistering threads from thread groups.
     // So we need to separate m_isShuttingDown from m_didExit.
     std::lock_guard<std::mutex> locker(m_mutex);

Modified: trunk/Source/WTF/wtf/Threading.h (225529 => 225530)


--- trunk/Source/WTF/wtf/Threading.h	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/wtf/Threading.h	2017-12-05 20:34:06 UTC (rev 225530)
@@ -56,8 +56,6 @@
 class AtomicStringTable;
 class ThreadMessageData;
 
-using AtomicStringTableDestructor = void (*)(AtomicStringTable*);
-
 enum class ThreadGroupAddResult;
 
 class ThreadGroup;
@@ -292,7 +290,6 @@
 
     AtomicStringTable* m_currentAtomicStringTable { nullptr };
     AtomicStringTable* m_defaultAtomicStringTable { nullptr };
-    AtomicStringTableDestructor m_atomicStringTableDestructor { nullptr };
 
 #if ENABLE(STACK_STATS)
     StackStats::PerThreadStats m_stackStats;

Modified: trunk/Source/WTF/wtf/mac/MainThreadMac.mm (225529 => 225530)


--- trunk/Source/WTF/wtf/mac/MainThreadMac.mm	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/wtf/mac/MainThreadMac.mm	2017-12-05 20:34:06 UTC (rev 225530)
@@ -168,6 +168,7 @@
     return pthread_main_np();
 }
 
+// Keep in mind that isWebThread can be called even when destroying the current thread.
 bool isWebThread()
 {
     return pthread_equal(pthread_self(), mainThreadPthread);

Modified: trunk/Source/WTF/wtf/text/AtomicStringTable.cpp (225529 => 225530)


--- trunk/Source/WTF/wtf/text/AtomicStringTable.cpp	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/wtf/text/AtomicStringTable.cpp	2017-12-05 20:34:06 UTC (rev 225530)
@@ -35,20 +35,12 @@
     // On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
     static AtomicStringTable* sharedStringTable = new AtomicStringTable;
 
-    bool currentThreadIsWebThread = isWebThread();
-    if (currentThreadIsWebThread || isUIThread())
+    if (isWebThread() || isUIThread()) {
         thread.m_defaultAtomicStringTable = sharedStringTable;
-    else
-        thread.m_defaultAtomicStringTable = new AtomicStringTable;
-
-    // We do the following so that its destruction happens only
-    // once - on the main UI thread.
-    if (!currentThreadIsWebThread)
-        thread.m_atomicStringTableDestructor = AtomicStringTable::destroy;
-#else
+        return;
+    }
+#endif // USE(WEB_THREAD)
     thread.m_defaultAtomicStringTable = new AtomicStringTable;
-    thread.m_atomicStringTableDestructor = AtomicStringTable::destroy;
-#endif // USE(WEB_THREAD)
 }
 
 AtomicStringTable::~AtomicStringTable()
@@ -59,6 +51,12 @@
 
 void AtomicStringTable::destroy(AtomicStringTable* table)
 {
+#if USE(WEB_THREAD)
+    // We do the following so that destruction of default atomic string table happens only
+    // once - on the main UI thread.
+    if (isWebThread())
+        return;
+#endif // USE(WEB_THREAD)
     delete table;
 }
 

Modified: trunk/Source/WTF/wtf/text/AtomicStringTable.h (225529 => 225530)


--- trunk/Source/WTF/wtf/text/AtomicStringTable.h	2017-12-05 20:26:37 UTC (rev 225529)
+++ trunk/Source/WTF/wtf/text/AtomicStringTable.h	2017-12-05 20:34:06 UTC (rev 225530)
@@ -37,11 +37,10 @@
     WTF_EXPORT_PRIVATE ~AtomicStringTable();
 
     static void create(Thread&);
+    static void destroy(AtomicStringTable*);
     HashSet<StringImpl*>& table() { return m_table; }
 
 private:
-    static void destroy(AtomicStringTable*);
-
     HashSet<StringImpl*> m_table;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to