Title: [148462] trunk/Source/WTF
- Revision
- 148462
- Author
- par...@webkit.org
- Date
- 2013-04-15 13:23:42 -0700 (Mon, 15 Apr 2013)
Log Message
[WIN] Remove remaining calls to pthread from WTF
https://bugs.webkit.org/show_bug.cgi?id=114563
Reviewed by Brent Fulgham.
Replace pthread_key_create with threadSpecificKeyCreate and
pthread_setspecific with threadSpecificSet from ThreadSpecific.h.
These functions provide a windows-specific implementation for the pthread functions,
but require that the thread has been created with WTF::createThread(),
which is the case for all threads created within WebKit.
To call this function from fastMalloc we must not call fastMalloc in them.
To fulfill this constraint ThreadSpecificWin will allocated its memory through the
original malloc implementation and use the stack for local and static variables.
Keep the Darwin implementation as it is, since it contains some performance tweaks.
* wtf/FastMalloc.cpp:
* wtf/ThreadSpecificWin.cpp:
(WTF::destructorsList):
(WTF::destructorsMutex):
(WTF::threadSpecificKeyCreate):
(WTF::threadSpecificKeyDelete):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (148461 => 148462)
--- trunk/Source/WTF/ChangeLog 2013-04-15 20:13:45 UTC (rev 148461)
+++ trunk/Source/WTF/ChangeLog 2013-04-15 20:23:42 UTC (rev 148462)
@@ -1,3 +1,27 @@
+2013-04-15 Patrick Gansterer <par...@webkit.org>
+
+ [WIN] Remove remaining calls to pthread from WTF
+ https://bugs.webkit.org/show_bug.cgi?id=114563
+
+ Reviewed by Brent Fulgham.
+
+ Replace pthread_key_create with threadSpecificKeyCreate and
+ pthread_setspecific with threadSpecificSet from ThreadSpecific.h.
+ These functions provide a windows-specific implementation for the pthread functions,
+ but require that the thread has been created with WTF::createThread(),
+ which is the case for all threads created within WebKit.
+ To call this function from fastMalloc we must not call fastMalloc in them.
+ To fulfill this constraint ThreadSpecificWin will allocated its memory through the
+ original malloc implementation and use the stack for local and static variables.
+ Keep the Darwin implementation as it is, since it contains some performance tweaks.
+
+ * wtf/FastMalloc.cpp:
+ * wtf/ThreadSpecificWin.cpp:
+ (WTF::destructorsList):
+ (WTF::destructorsMutex):
+ (WTF::threadSpecificKeyCreate):
+ (WTF::threadSpecificKeyDelete):
+
2013-04-14 Oliver Hunt <oli...@apple.com>
Try to fix non-apple windows builds
Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (148461 => 148462)
--- trunk/Source/WTF/wtf/FastMalloc.cpp 2013-04-15 20:13:45 UTC (rev 148461)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp 2013-04-15 20:23:42 UTC (rev 148462)
@@ -428,6 +428,7 @@
#include "TCPageMap.h"
#include "TCSpinLock.h"
#include "TCSystemAlloc.h"
+#include "ThreadSpecific.h"
#include <algorithm>
#include <pthread.h>
#include <stdarg.h>
@@ -2841,11 +2842,8 @@
#if USE(PTHREAD_GETSPECIFIC_DIRECT)
static const pthread_key_t heap_key = __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0;
#else
-static pthread_key_t heap_key;
+static ThreadSpecificKey heap_key;
#endif
-#if OS(WINDOWS)
-DWORD tlsIndex = TLS_OUT_OF_INDEXES;
-#endif
static ALWAYS_INLINE void setThreadHeap(TCMalloc_ThreadCache* heap)
{
@@ -2856,12 +2854,12 @@
CRASH();
#endif
+#if OS(DARWIN)
// Still do pthread_setspecific even if there's an alternate form
// of thread-local storage in use, to benefit from the delete callback.
pthread_setspecific(heap_key, heap);
-
-#if OS(WINDOWS)
- TlsSetValue(tlsIndex, heap);
+#else
+ threadSpecificSet(heap_key, heap);
#endif
}
@@ -3407,10 +3405,10 @@
// __thread is faster, but only when the kernel supports it
if (KernelSupportsTLS())
return threadlocal_heap;
-#elif OS(WINDOWS)
- return static_cast<TCMalloc_ThreadCache*>(TlsGetValue(tlsIndex));
-#else
+#elif OS(DARWIN)
return static_cast<TCMalloc_ThreadCache*>(pthread_getspecific(heap_key));
+#else
+ return static_cast<TCMalloc_ThreadCache*>(threadSpecificGet(heap_key));
#endif
}
@@ -3439,11 +3437,8 @@
#if USE(PTHREAD_GETSPECIFIC_DIRECT)
pthread_key_init_np(heap_key, DestroyThreadCache);
#else
- pthread_key_create(&heap_key, DestroyThreadCache);
+ threadSpecificKeyCreate(&heap_key, DestroyThreadCache);
#endif
-#if OS(WINDOWS)
- tlsIndex = TlsAlloc();
-#endif
tsd_inited = true;
#if !OS(WINDOWS)
Modified: trunk/Source/WTF/wtf/ThreadSpecificWin.cpp (148461 => 148462)
--- trunk/Source/WTF/wtf/ThreadSpecificWin.cpp 2013-04-15 20:13:45 UTC (rev 148461)
+++ trunk/Source/WTF/wtf/ThreadSpecificWin.cpp 2013-04-15 20:23:42 UTC (rev 148462)
@@ -34,13 +34,13 @@
static DoublyLinkedList<PlatformThreadSpecificKey>& destructorsList()
{
- DEFINE_STATIC_LOCAL(DoublyLinkedList<PlatformThreadSpecificKey>, staticList, ());
+ static DoublyLinkedList<PlatformThreadSpecificKey> staticList;
return staticList;
}
static Mutex& destructorsMutex()
{
- DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
+ static Mutex staticMutex;
return staticMutex;
}
@@ -91,7 +91,9 @@
void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
{
- *key = new PlatformThreadSpecificKey(destructor);
+ // 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);
@@ -101,7 +103,8 @@
{
MutexLocker locker(destructorsMutex());
destructorsList().remove(key);
- delete key;
+ key->~PlatformThreadSpecificKey();
+ ::free(key);
}
void threadSpecificSet(ThreadSpecificKey key, void* data)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes