about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <mwrap-perl@80x24.org>2022-09-03 11:18:25 +0000
committerEric Wong <e@80x24.org>2022-09-04 06:59:46 +0000
commit38c97ffc04d3254cdc64bc46bf6b28c016599037 (patch)
tree38fc02a11e1125467bb11d87442605bdf56a92ea
parent49ef0e679662504157e55cf890fd00480c6443ec (diff)
downloadmwrap-38c97ffc04d3254cdc64bc46bf6b28c016599037.tar.gz
__thread is a gcc-ism which clang supports, but _Thread_local is
part of C11 and more likely to be supported by future compilers.
-rw-r--r--Mwrap.xs12
1 files changed, 10 insertions, 2 deletions
diff --git a/Mwrap.xs b/Mwrap.xs
index bb51930..e888a1c 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -26,6 +26,14 @@
 #include <urcu/rculist.h>
 #include "jhash.h"
 
+#if __STDC_VERSION__ >= 201112
+#        define MWRAP_TSD _Thread_local
+#elif defined(__GNUC__)
+#        define MWRAP_TSD __thread
+#else
+#        error _Thread_local nor __thread supported
+#endif
+
 /*
  * Perl doesn't have a GC the same way (C) Ruby does, so no GC count.
  * Instead, the relative age of an object is the number of total bytes
@@ -62,7 +70,7 @@ static int resolving_malloc;
         } \
 } while (0)
 
-static __thread size_t locating;
+static MWRAP_TSD size_t locating;
 #ifndef PERL_IMPLICIT_CONTEXT
 static size_t *root_locating; /* determines if PL_curcop is our thread */
 #endif
@@ -237,7 +245,7 @@ struct alloc_hdr {
         size_t size;
 };
 
-static __thread char kbuf[
+static MWRAP_TSD char kbuf[
         PATH_MAX + INT2STR_MAX + sizeof(struct alloc_hdr) + 2
 ];