Mark CrapPool thread_local
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 24 May 2018 18:46:57 +0000 (11:46 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 24 May 2018 20:53:02 +0000 (13:53 -0700)
Not sure if I like to keep it. For now, aim for correctness.

src/dump-emoji.cc
src/dump-fon.cc
src/hb-ot-layout.cc
src/hb-private.hh
src/hb-subset.cc
src/main.cc

index 50a929b..280c5c9 100644 (file)
@@ -48,7 +48,7 @@
 
 #ifndef HB_NO_VISIBILITY
 const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
 #endif
 
 void cbdt_callback (const uint8_t* data, unsigned int length,
index 827de4a..748de1a 100644 (file)
@@ -28,7 +28,7 @@
 
 #ifndef HB_NO_VISIBILITY
 const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
 #endif
 
 template <typename Type, int Bytes> struct LEInt;
index 6704954..7f9b6be 100644 (file)
@@ -48,7 +48,7 @@
 
 #ifndef HB_NO_VISIBILITY
 const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
 #endif
 
 
index 4318eb9..45f6990 100644 (file)
@@ -90,6 +90,14 @@ extern "C" void  hb_free_impl(void *ptr);
        HB_UNUSED typedef int HB_PASTE(static_assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1]
 #endif // static_assert
 
+#ifdef __GNUC__
+#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
+#define thread_local __thread
+#endif
+#else
+#define thread_local
+#endif
+
 #endif // __cplusplus < 201103L
 
 #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__)
@@ -570,12 +578,16 @@ static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool
 
 /* Global writable pool.  Enlarge as necessary. */
 
+/* To be fully correct, CrapPool must be thread_local. However, we do not rely on CrapPool
+ * for correct operation. It only exist to catch and divert program logic bugs instead of
+ * causing bad memory access. So, races there are not actually introducing incorrectness
+ * in the code. So maybe disable? Has ~12kb binary size overhead to have it. */
 #ifdef HB_NO_VISIBILITY
 static
 #else
 extern HB_INTERNAL
 #endif
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)]
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)]
 #ifdef HB_NO_VISIBILITY
 = {}
 #endif
index ad273d0..e974d0f 100644 (file)
@@ -46,7 +46,7 @@
 
 #if !defined(HB_NO_VISIBILITY) && !defined(HB_SUBSET_BUILTIN)
 const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
 #endif
 
 
index f32490e..2fec52f 100644 (file)
@@ -39,7 +39,7 @@ using namespace OT;
 
 #ifndef HB_NO_VISIBILITY
 const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
-void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
+thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
 #endif
 
 int