diff options
-rw-r--r-- | Source/JavaScriptCore/ChangeLog | 18 | ||||
-rw-r--r-- | Source/JavaScriptCore/heap/MachineStackMarker.cpp | 14 | ||||
-rw-r--r-- | Source/JavaScriptCore/heap/MachineStackMarker.h | 4 | ||||
-rw-r--r-- | Source/WTF/wtf/ThreadSpecific.h | 36 | ||||
-rw-r--r-- | Source/WTF/wtf/ThreadSpecificWin.cpp | 90 |
5 files changed, 147 insertions, 15 deletions
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index a1cbefa36..f0e93b012 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,21 @@ +2012-06-13 Patrick Gansterer <paroga@webkit.org> + + [WIN] Remove dependency on pthread from MachineStackMarker + https://bugs.webkit.org/show_bug.cgi?id=68429 + + Reviewed by NOBODY (OOPS!). + + Implement pthread TLS functionality with native windows functions. + + * heap/MachineStackMarker.cpp: Use the new functions instead of pthread directly. + * heap/MachineStackMarker.h: + * wtf/ThreadSpecific.h: + (WTF::ThreadSpecificKeyCreate): Added wrapper around pthread_key_create. + (WTF::ThreadSpecificKeyDelete): Added wrapper around pthread_key_delete. + (WTF::ThreadSpecificSet): Added wrapper around pthread_setspecific. + (WTF::ThreadSpecificGet): Added wrapper around pthread_getspecific. + * wtf/ThreadSpecificWin.cpp: + 2012-07-10 Filip Pizlo <fpizlo@apple.com> REGRESSION(r122166): It made 170 tests crash on 32 bit platforms diff --git a/Source/JavaScriptCore/heap/MachineStackMarker.cpp b/Source/JavaScriptCore/heap/MachineStackMarker.cpp index 7eb57479b..8e0c57b6a 100644 --- a/Source/JavaScriptCore/heap/MachineStackMarker.cpp +++ b/Source/JavaScriptCore/heap/MachineStackMarker.cpp @@ -141,10 +141,8 @@ MachineThreads::MachineThreads(Heap* heap) MachineThreads::~MachineThreads() { - if (m_threadSpecific) { - int error = pthread_key_delete(m_threadSpecific); - ASSERT_UNUSED(error, !error); - } + if (m_threadSpecific) + ThreadSpecificKeyDelete(m_threadSpecific); MutexLocker registeredThreadsLock(m_registeredThreadsMutex); for (Thread* t = m_registeredThreads; t;) { @@ -181,19 +179,17 @@ void MachineThreads::makeUsableFromMultipleThreads() if (m_threadSpecific) return; - int error = pthread_key_create(&m_threadSpecific, removeThread); - if (error) - CRASH(); + ThreadSpecificKeyCreate(&m_threadSpecific, removeThread); } void MachineThreads::addCurrentThread() { ASSERT(!m_heap->globalData()->exclusiveThread || m_heap->globalData()->exclusiveThread == currentThread()); - if (!m_threadSpecific || pthread_getspecific(m_threadSpecific)) + if (!m_threadSpecific || ThreadSpecificGet(m_threadSpecific)) return; - pthread_setspecific(m_threadSpecific, this); + ThreadSpecificSet(m_threadSpecific, this); Thread* thread = new Thread(getCurrentPlatformThread(), wtfThreadData().stack().origin()); MutexLocker lock(m_registeredThreadsMutex); diff --git a/Source/JavaScriptCore/heap/MachineStackMarker.h b/Source/JavaScriptCore/heap/MachineStackMarker.h index 5c7705fcf..3d4aa22d4 100644 --- a/Source/JavaScriptCore/heap/MachineStackMarker.h +++ b/Source/JavaScriptCore/heap/MachineStackMarker.h @@ -22,8 +22,8 @@ #ifndef MachineThreads_h #define MachineThreads_h -#include <pthread.h> #include <wtf/Noncopyable.h> +#include <wtf/ThreadSpecific.h> #include <wtf/ThreadingPrimitives.h> namespace JSC { @@ -55,7 +55,7 @@ namespace JSC { Heap* m_heap; Mutex m_registeredThreadsMutex; Thread* m_registeredThreads; - pthread_key_t m_threadSpecific; + WTF::ThreadSpecificKey m_threadSpecific; }; } // namespace JSC diff --git a/Source/WTF/wtf/ThreadSpecific.h b/Source/WTF/wtf/ThreadSpecific.h index f51ab4cf2..60c9907bd 100644 --- a/Source/WTF/wtf/ThreadSpecific.h +++ b/Source/WTF/wtf/ThreadSpecific.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Apple Inc. All rights reserved. * Copyright (C) 2009 Jian Li <jianli@chromium.org> + * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -102,6 +103,33 @@ private: }; #if USE(PTHREADS) + +typedef pthread_key_t ThreadSpecificKey; + +inline void ThreadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *)) +{ + int error = pthread_key_create(key, destructor); + if (error) + CRASH(); +} + +inline void ThreadSpecificKeyDelete(ThreadSpecificKey key) +{ + int error = pthread_key_delete(key); + if (error) + CRASH(); +} + +inline void ThreadSpecificSet(ThreadSpecificKey key, void* value) +{ + pthread_setspecific(key, value); +} + +inline void* ThreadSpecificGet(ThreadSpecificKey key) +{ + return pthread_getspecific(key); +} + template<typename T> inline ThreadSpecific<T>::ThreadSpecific() { @@ -139,6 +167,14 @@ const int kMaxTlsKeySize = 256; WTF_EXPORT_PRIVATE long& tlsKeyCount(); WTF_EXPORT_PRIVATE DWORD* tlsKeys(); +class ThreadSpecificKeyValue; +typedef ThreadSpecificKeyValue* ThreadSpecificKey; + +void ThreadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void *)); +void ThreadSpecificKeyDelete(ThreadSpecificKey); +void ThreadSpecificSet(ThreadSpecificKey, void*); +void* ThreadSpecificGet(ThreadSpecificKey); + template<typename T> inline ThreadSpecific<T>::ThreadSpecific() : m_index(-1) diff --git a/Source/WTF/wtf/ThreadSpecificWin.cpp b/Source/WTF/wtf/ThreadSpecificWin.cpp index d72996a7a..61a594251 100644 --- a/Source/WTF/wtf/ThreadSpecificWin.cpp +++ b/Source/WTF/wtf/ThreadSpecificWin.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Jian Li <jianli@chromium.org> + * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,15 +20,72 @@ */ #include "config.h" - #include "ThreadSpecific.h" -#if USE(PTHREADS) -#error This file should not be compiled by ports that do not use Windows native ThreadSpecific implementation. -#endif +#include "StdLibExtras.h" +#include "ThreadingPrimitives.h" + +#if !USE(PTHREADS) namespace WTF { +static Mutex& destructorsMutex() +{ + DEFINE_STATIC_LOCAL(Mutex, staticMutex, ()); + return staticMutex; +} + +class ThreadSpecificKeyValue { +public: + ThreadSpecificKeyValue(void (*destructor)(void *)) + : m_destructor(destructor) + { + m_tlsKey = TlsAlloc(); + if (m_tlsKey == TLS_OUT_OF_INDEXES) + CRASH(); + + MutexLocker locker(destructorsMutex()); + m_next = m_first; + m_first = this; + } + + ~ThreadSpecificKeyValue() + { + MutexLocker locker(destructorsMutex()); + ThreadSpecificKeyValue** next = &m_first; + while (*next != this) { + ASSERT(*next); + next = &(*next)->m_next; + } + *next = (*next)->m_next; + + TlsFree(m_tlsKey); + } + + void setValue(void* data) { TlsSetValue(m_tlsKey, data); } + void* value() { return TlsGetValue(m_tlsKey); } + + static void callDestructors() + { + MutexLocker locker(destructorsMutex()); + ThreadSpecificKeyValue* next = m_first; + while (next) { + if (void* data = next->value()) + next->m_destructor(data); + next = next->m_next; + } + } + +private: + void (*m_destructor)(void *); + DWORD m_tlsKey; + ThreadSpecificKeyValue* m_next; + + static ThreadSpecificKeyValue* m_first; +}; + +ThreadSpecificKeyValue* ThreadSpecificKeyValue::m_first = 0; + long& tlsKeyCount() { static long count; @@ -40,6 +98,26 @@ DWORD* tlsKeys() return keys; } +void ThreadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *)) +{ + *key = new ThreadSpecificKeyValue(destructor); +} + +void ThreadSpecificKeyDelete(ThreadSpecificKey key) +{ + delete 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++) { @@ -48,6 +126,10 @@ void ThreadSpecificThreadExit() if (data) data->destructor(data); } + + ThreadSpecificKeyValue::callDestructors(); } } // namespace WTF + +#endif // !USE(PTHREADS) |