]> Sergey Matveev's repositories - bfs.git/commitdiff
thread: Define thread_local
authorTavian Barnes <tavianator@tavianator.com>
Thu, 5 Oct 2023 16:55:56 +0000 (12:55 -0400)
committerTavian Barnes <tavianator@tavianator.com>
Thu, 5 Oct 2023 16:55:56 +0000 (12:55 -0400)
src/config.h
src/thread.h

index e3048c4d8e17098f88b9c6b3777bd3fd0efe21b1..862a839b45bf6573790e6a6adf4fb312eb4760c1 100644 (file)
@@ -59,6 +59,9 @@
 #if __has_include(<sys/xattr.h>)
 #  define BFS_HAS_SYS_XATTR_H true
 #endif
+#if __has_include(<threads.h>)
+#  define BFS_HAS_THREADS_H true
+#endif
 #if __has_include(<util.h>)
 #  define BFS_HAS_UTIL_H true
 #endif
@@ -74,6 +77,7 @@
 #define BFS_HAS_SYS_PARAM_H true
 #define BFS_HAS_SYS_SYSMACROS_H __GLIBC__
 #define BFS_HAS_SYS_XATTR_H __linux__
+#define BFS_HAS_THREADS_H (!__STDC_NO_THREADS__)
 #define BFS_HAS_UTIL_H __NetBSD__
 
 #endif // !__has_include
 #ifndef BFS_USE_SYS_XATTR_H
 #  define BFS_USE_SYS_XATTR_H BFS_HAS_SYS_XATTR_H
 #endif
+#ifndef BFS_USE_THREADS_H
+#  define BFS_USE_THREADS_H BFS_HAS_THREADS_H
+#endif
 #ifndef BFS_USE_UTIL_H
 #  define BFS_USE_UTIL_H BFS_HAS_UTIL_H
 #endif
index 45b5e1f703d23c140939f68288746821c6c5179a..ab95a7949b05f6f1b1dace59801fa49779c210f6 100644 (file)
@@ -8,11 +8,20 @@
 #ifndef BFS_THREAD_H
 #define BFS_THREAD_H
 
+#include "config.h"
 #include "diag.h"
 #include <errno.h>
 #include <pthread.h>
 #include <string.h>
 
+#if __STDC_VERSION__ < 202311L && !defined(thread_local)
+#  if BFS_USE_THREADS_H
+#    include <threads.h>
+#  else
+#    define thread_local _Thread_local
+#  endif
+#endif
+
 #define thread_verify(expr, cond) \
        bfs_verify((errno = (expr), (cond)), "%s: %s", #expr, strerror(errno))