Title: [199679] trunk/Source/WTF
Revision
199679
Author
[email protected]
Date
2016-04-18 10:30:36 -0700 (Mon, 18 Apr 2016)

Log Message

Unreviewed, rolling out r199621.
https://bugs.webkit.org/show_bug.cgi?id=156708

made windows tests crash (Requested by alexchristensen on
#webkit).

Reverted changeset:

"iTunes crashing _javascript_Core.dll"
https://bugs.webkit.org/show_bug.cgi?id=156647
http://trac.webkit.org/changeset/199621

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (199678 => 199679)


--- trunk/Source/WTF/ChangeLog	2016-04-18 17:28:40 UTC (rev 199678)
+++ trunk/Source/WTF/ChangeLog	2016-04-18 17:30:36 UTC (rev 199679)
@@ -1,3 +1,17 @@
+2016-04-18  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r199621.
+        https://bugs.webkit.org/show_bug.cgi?id=156708
+
+        made windows tests crash (Requested by alexchristensen on
+        #webkit).
+
+        Reverted changeset:
+
+        "iTunes crashing _javascript_Core.dll"
+        https://bugs.webkit.org/show_bug.cgi?id=156647
+        http://trac.webkit.org/changeset/199621
+
 2016-04-15  Michael Saboff  <[email protected]>
 
         iTunes crashing _javascript_Core.dll

Modified: trunk/Source/WTF/wtf/ThreadSpecific.h (199678 => 199679)


--- trunk/Source/WTF/wtf/ThreadSpecific.h	2016-04-18 17:28:40 UTC (rev 199678)
+++ trunk/Source/WTF/wtf/ThreadSpecific.h	2016-04-18 17:30:36 UTC (rev 199679)
@@ -94,6 +94,9 @@
 
         T* value;
         ThreadSpecific<T>* owner;
+#if OS(WINDOWS)
+        void (*destructor)(void*);
+#endif
     };
 
 #if USE(PTHREADS)
@@ -155,64 +158,47 @@
 
 #elif OS(WINDOWS)
 
-// The maximum number of FLS keys that can be created. For simplification, we assume that:
+// The maximum number of TLS keys that can be created. For simplification, we assume that:
 // 1) Once the instance of ThreadSpecific<> is created, it will not be destructed until the program dies.
 // 2) We do not need to hold many instances of ThreadSpecific<> data. This fixed number should be far enough.
-const int kMaxFlsKeySize = 100;
+const int kMaxTlsKeySize = 256;
 
-WTF_EXPORT_PRIVATE long& flsKeyCount();
-WTF_EXPORT_PRIVATE DWORD* flsKeys();
+WTF_EXPORT_PRIVATE long& tlsKeyCount();
+WTF_EXPORT_PRIVATE DWORD* tlsKeys();
 
-typedef DWORD ThreadSpecificKey;
+class PlatformThreadSpecificKey;
+typedef PlatformThreadSpecificKey* ThreadSpecificKey;
 
-inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
-{
-    DWORD flsKey = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destructor));
-    if (flsKey == FLS_OUT_OF_INDEXES)
-        CRASH();
+WTF_EXPORT_PRIVATE void threadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void *));
+WTF_EXPORT_PRIVATE void threadSpecificKeyDelete(ThreadSpecificKey);
+WTF_EXPORT_PRIVATE void threadSpecificSet(ThreadSpecificKey, void*);
+WTF_EXPORT_PRIVATE void* threadSpecificGet(ThreadSpecificKey);
 
-    *key = flsKey;
-}
-
-inline void threadSpecificKeyDelete(ThreadSpecificKey key)
-{
-    FlsFree(key);
-}
-
-inline void threadSpecificSet(ThreadSpecificKey key, void* data)
-{
-    FlsSetValue(key, data);
-}
-
-inline void* threadSpecificGet(ThreadSpecificKey key)
-{
-    return FlsGetValue(key);
-}
-
 template<typename T>
 inline ThreadSpecific<T>::ThreadSpecific()
     : m_index(-1)
 {
-    DWORD flsKey = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destroy));
-    if (flsKey == FLS_OUT_OF_INDEXES)
+    DWORD tlsKey = TlsAlloc();
+    if (tlsKey == TLS_OUT_OF_INDEXES)
         CRASH();
 
-    m_index = InterlockedIncrement(&flsKeyCount()) - 1;
-    if (m_index >= kMaxFlsKeySize)
+    m_index = InterlockedIncrement(&tlsKeyCount()) - 1;
+    if (m_index >= kMaxTlsKeySize)
         CRASH();
-    flsKeys()[m_index] = flsKey;
+    tlsKeys()[m_index] = tlsKey;
 }
 
 template<typename T>
 inline ThreadSpecific<T>::~ThreadSpecific()
 {
-    FlsFree(flsKeys()[m_index]);
+    // Does not invoke destructor functions. They will be called from ThreadSpecificThreadExit when the thread is detached.
+    TlsFree(tlsKeys()[m_index]);
 }
 
 template<typename T>
 inline T* ThreadSpecific<T>::get()
 {
-    Data* data = ""
+    Data* data = ""
     return data ? data->value : 0;
 }
 
@@ -221,7 +207,8 @@
 {
     ASSERT(!get());
     Data* data = "" Data(ptr, this);
-    FlsSetValue(flsKeys()[m_index], data);
+    data->destructor = &ThreadSpecific<T>::destroy;
+    TlsSetValue(tlsKeys()[m_index], data);
 }
 
 #else
@@ -245,7 +232,7 @@
 #if USE(PTHREADS)
     pthread_setspecific(data->owner->m_key, 0);
 #elif OS(WINDOWS)
-    FlsSetValue(flsKeys()[data->owner->m_index], 0);
+    TlsSetValue(tlsKeys()[data->owner->m_index], 0);
 #else
 #error ThreadSpecific is not implemented for this platform.
 #endif

Modified: trunk/Source/WTF/wtf/ThreadSpecificWin.cpp (199678 => 199679)


--- trunk/Source/WTF/wtf/ThreadSpecificWin.cpp	2016-04-18 17:28:40 UTC (rev 199678)
+++ trunk/Source/WTF/wtf/ThreadSpecificWin.cpp	2016-04-18 17:30:36 UTC (rev 199679)
@@ -24,22 +24,117 @@
 
 #if OS(WINDOWS)
 
+#include "StdLibExtras.h"
+#include "ThreadingPrimitives.h"
+#include <wtf/DoublyLinkedList.h>
+
 #if !USE(PTHREADS)
 
 namespace WTF {
 
-long& flsKeyCount()
+static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList()
 {
+    static DoublyLinkedList<PlatformThreadSpecificKey> staticList;
+    return staticList;
+}
+
+static Mutex& destructorsMutex()
+{
+    static Mutex staticMutex;
+    return staticMutex;
+}
+
+class PlatformThreadSpecificKey : public DoublyLinkedListNode<PlatformThreadSpecificKey> {
+public:
+    friend class DoublyLinkedListNode<PlatformThreadSpecificKey>;
+
+    PlatformThreadSpecificKey(void (*destructor)(void *))
+        : m_destructor(destructor)
+    {
+        m_tlsKey = TlsAlloc();
+        if (m_tlsKey == TLS_OUT_OF_INDEXES)
+            CRASH();
+    }
+
+    ~PlatformThreadSpecificKey()
+    {
+        TlsFree(m_tlsKey);
+    }
+
+    void setValue(void* data) { TlsSetValue(m_tlsKey, data); }
+    void* value() { return TlsGetValue(m_tlsKey); }
+
+    void callDestructor()
+    {
+       if (void* data = ""
+            m_destructor(data);
+    }
+
+private:
+    void (*m_destructor)(void *);
+    DWORD m_tlsKey;
+    PlatformThreadSpecificKey* m_prev;
+    PlatformThreadSpecificKey* m_next;
+};
+
+long& tlsKeyCount()
+{
     static long count;
     return count;
 }
 
-DWORD* flsKeys()
+DWORD* tlsKeys()
 {
-    static DWORD keys[kMaxFlsKeySize];
+    static DWORD keys[kMaxTlsKeySize];
     return keys;
 }
 
+void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
+{
+    // Use the original malloc() instead of fastMalloc() to use this function in FastMalloc code.
+    *key = static_cast<PlatformThreadSpecificKey*>(::malloc(sizeof(PlatformThreadSpecificKey)));
+    new (*key) PlatformThreadSpecificKey(destructor);
+
+    MutexLocker locker(destructorsMutex());
+    destructorsList().push(*key);
+}
+
+void threadSpecificKeyDelete(ThreadSpecificKey key)
+{
+    MutexLocker locker(destructorsMutex());
+    destructorsList().remove(key);
+    key->~PlatformThreadSpecificKey();
+    ::free(key);
+}
+
+void threadSpecificSet(ThreadSpecificKey key, void* data)
+{
+    key->setValue(data);
+}
+
+void* threadSpecificGet(ThreadSpecificKey key)
+{
+    return key->value();
+}
+
+void ThreadSpecificThreadExit()
+{
+    for (long i = 0; i < tlsKeyCount(); i++) {
+        // The layout of ThreadSpecific<T>::Data does not depend on T. So we are safe to do the static cast to ThreadSpecific<int> in order to access its data member.
+        ThreadSpecific<int>::Data* data = ""
+        if (data)
+            data->destructor(data);
+    }
+
+    MutexLocker locker(destructorsMutex());
+    PlatformThreadSpecificKey* key = destructorsList().head();
+    while (key) {
+        PlatformThreadSpecificKey* nextKey = key->next();
+        key->callDestructor();
+        key = nextKey;
+    }
+}
+
 } // namespace WTF
 
 #endif // !USE(PTHREADS)

Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (199678 => 199679)


--- trunk/Source/WTF/wtf/ThreadingWin.cpp	2016-04-18 17:28:40 UTC (rev 199678)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp	2016-04-18 17:30:36 UTC (rev 199679)
@@ -102,6 +102,10 @@
 #include <wtf/RandomNumberSeed.h>
 #include <wtf/WTFThreadData.h>
 
+#if !USE(PTHREADS) && OS(WINDOWS)
+#include "ThreadSpecific.h"
+#endif
+
 #if HAVE(ERRNO_H)
 #include <errno.h>
 #endif
@@ -195,6 +199,11 @@
     std::unique_ptr<ThreadFunctionInvocation> invocation(static_cast<ThreadFunctionInvocation*>(param));
     invocation->function(invocation->data);
 
+#if !USE(PTHREADS) && OS(WINDOWS)
+    // Do the TLS cleanup.
+    ThreadSpecificThreadExit();
+#endif
+
     return 0;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to