Title: [172576] trunk/Source/bmalloc
Revision
172576
Author
[email protected]
Date
2014-08-13 22:00:22 -0700 (Wed, 13 Aug 2014)

Log Message

Make bmalloc::PerThread work without C++ thread local storage
https://bugs.webkit.org/show_bug.cgi?id=135895

Reviewed by Geoffrey Garen.

Implement support for building bmalloc without C++ thread local storage.

* bmalloc/BPlatform.h: Remove macro define BPLATFORM_IOS_SIMULATOR. Added macro function
BCOMPILER_SUPPORTS() and macro define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL that can be used
to determine whether the compiler supports C++ thread local storage.
* bmalloc/PerThread.h:
(bmalloc::PerThreadStorage::get): Modified to call pthread_getspecific() when building
without C++ thread local storage.
(bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Added.
(bmalloc::PerThreadStorage::init): Moved logic to initialize shared Pthread key from here to
PerThreadStorage::initSharedKeyIfNeeded().
(bmalloc::PerThread<T>::getFastCase): Modified to call PerThreadStorage::initSharedKeyIfNeeded()
before querying PerThreadStorage::get() when building without C++ thread local storage so as to
ensure that the shared key has been initialized.
(_pthread_setspecific_direct): Deleted.
(_pthread_getspecific_direct): Deleted.

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (172575 => 172576)


--- trunk/Source/bmalloc/ChangeLog	2014-08-14 04:25:07 UTC (rev 172575)
+++ trunk/Source/bmalloc/ChangeLog	2014-08-14 05:00:22 UTC (rev 172576)
@@ -1,5 +1,29 @@
 2014-08-13  Daniel Bates  <[email protected]>
 
+        Make bmalloc::PerThread work without C++ thread local storage
+        https://bugs.webkit.org/show_bug.cgi?id=135895
+
+        Reviewed by Geoffrey Garen.
+
+        Implement support for building bmalloc without C++ thread local storage.
+
+        * bmalloc/BPlatform.h: Remove macro define BPLATFORM_IOS_SIMULATOR. Added macro function
+        BCOMPILER_SUPPORTS() and macro define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL that can be used
+        to determine whether the compiler supports C++ thread local storage.
+        * bmalloc/PerThread.h:
+        (bmalloc::PerThreadStorage::get): Modified to call pthread_getspecific() when building
+        without C++ thread local storage.
+        (bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Added.
+        (bmalloc::PerThreadStorage::init): Moved logic to initialize shared Pthread key from here to
+        PerThreadStorage::initSharedKeyIfNeeded().
+        (bmalloc::PerThread<T>::getFastCase): Modified to call PerThreadStorage::initSharedKeyIfNeeded()
+        before querying PerThreadStorage::get() when building without C++ thread local storage so as to
+        ensure that the shared key has been initialized.
+        (_pthread_setspecific_direct): Deleted.
+        (_pthread_getspecific_direct): Deleted.
+
+2014-08-13  Daniel Bates  <[email protected]>
+
         [iOS] Make _javascript_Core and bmalloc build with the public SDK
         https://bugs.webkit.org/show_bug.cgi?id=135848
 

Modified: trunk/Source/bmalloc/bmalloc/BPlatform.h (172575 => 172576)


--- trunk/Source/bmalloc/bmalloc/BPlatform.h	2014-08-14 04:25:07 UTC (rev 172575)
+++ trunk/Source/bmalloc/bmalloc/BPlatform.h	2014-08-14 05:00:22 UTC (rev 172576)
@@ -38,8 +38,7 @@
 #define BPLATFORM_IOS 1
 #endif
 
-#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
-#define BPLATFORM_IOS_SIMULATOR 1
-#endif
+#define BCOMPILER_SUPPORTS(COMPILER_FEATURE) (defined BCOMPILER_SUPPORTS_##COMPILER_FEATURE && BCOMPILER_SUPPORTS_##COMPILER_FEATURE)
+#define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL (defined(__has_feature) && __has_feature(cxx_thread_local))
 
 #endif // BPlatform_h

Modified: trunk/Source/bmalloc/bmalloc/PerThread.h (172575 => 172576)


--- trunk/Source/bmalloc/bmalloc/PerThread.h	2014-08-14 04:25:07 UTC (rev 172575)
+++ trunk/Source/bmalloc/bmalloc/PerThread.h	2014-08-14 05:00:22 UTC (rev 172576)
@@ -32,15 +32,6 @@
 #include <pthread.h>
 #if defined(__has_include) && __has_include(<System/pthread_machdep.h>)
 #include <System/pthread_machdep.h>
-#elif BPLATFORM(IOS_SIMULATOR)
-// FIXME: We shouldn't hardcode this constant as it can become out-of-date with the macro define of the same
-// name in System/pthread_machdep.h. Instead, we should make PerThread work without C++ thread local storage.
-// See <https://bugs.webkit.org/show_bug.cgi?id=135895> for more details.
-const pthread_key_t __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0 = 90;
-
-INLINE int _pthread_setspecific_direct(pthread_key_t key, const void* value) { return pthread_setspecific(key, value); }
-INLINE void* _pthread_getspecific_direct(pthread_key_t key) { return pthread_getspecific(key); }
-extern "C" int pthread_key_init_np(int, void (*destructor)(void*));
 #endif
 
 namespace bmalloc {
@@ -63,7 +54,7 @@
 
 template<typename T> struct PerThreadStorage;
 
-#if (defined(__has_include) && __has_include(<System/pthread_machdep.h>)) || BPLATFORM(IOS_SIMULATOR)
+#if defined(__has_include) && __has_include(<System/pthread_machdep.h>)
 // For now, we only support PerThread<Cache>. We can expand to other types by
 // using more keys.
 
@@ -80,30 +71,52 @@
 #else
 
 template<typename T> struct PerThreadStorage {
+#if BCOMPILER_SUPPORTS(CXX_THREAD_LOCAL)
     static __thread void* object;
+#endif
     static pthread_key_t key;
     static std::once_flag onceFlag;
 
-    static void* get() { return object; }
-    static void init(void* object, void (*destructor)(void*))
+    static void* get()
     {
+#if BCOMPILER_SUPPORTS(CXX_THREAD_LOCAL)
+        return object;
+#else
+        return pthread_getspecific(key);
+#endif
+    }
+
+    static void initSharedKeyIfNeeded(void (*destructor)(void*))
+    {
         std::call_once(onceFlag, [destructor]() {
             pthread_key_create(&key, destructor);
         });
+    }
+
+    static void init(void* object, void (*destructor)(void*))
+    {
+        initSharedKeyIfNeeded(destructor);
         pthread_setspecific(key, object);
+#if BCOMPILER_SUPPORTS(CXX_THREAD_LOCAL)
         PerThreadStorage<Cache>::object = object;
+#endif
     }
 };
 
+#if BCOMPILER_SUPPORTS(CXX_THREAD_LOCAL)
 template<typename T> __thread void* PerThreadStorage<T>::object;
+#endif
 template<typename T> pthread_key_t PerThreadStorage<T>::key;
 template<typename T> std::once_flag PerThreadStorage<T>::onceFlag;
 
-#endif // (defined(__has_include) && __has_include(<System/pthread_machdep.h>)) || BPLATFORM(IOS_SIMULATOR)
+#endif // defined(__has_include) && __has_include(<System/pthread_machdep.h>)
 
 template<typename T>
 INLINE T* PerThread<T>::getFastCase()
 {
+#if (!defined(__has_include) || !__has_include(<System/pthread_machdep.h>)) && !BCOMPILER_SUPPORTS(CXX_THREAD_LOCAL)
+    initSharedKeyIfNeeded(destructor);
+#endif
     return static_cast<T*>(PerThreadStorage<T>::get());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to