From 634359bb169311646f6369b21f0c90a9819fe2ce Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 5 Oct 2023 12:55:56 -0400 Subject: thread: Define thread_local --- src/config.h | 7 +++++++ src/thread.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/config.h b/src/config.h index e3048c4..862a839 100644 --- a/src/config.h +++ b/src/config.h @@ -59,6 +59,9 @@ #if __has_include() # define BFS_HAS_SYS_XATTR_H true #endif +#if __has_include() +# define BFS_HAS_THREADS_H true +#endif #if __has_include() # 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 @@ -105,6 +109,9 @@ #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 diff --git a/src/thread.h b/src/thread.h index 45b5e1f..ab95a79 100644 --- a/src/thread.h +++ b/src/thread.h @@ -8,11 +8,20 @@ #ifndef BFS_THREAD_H #define BFS_THREAD_H +#include "config.h" #include "diag.h" #include #include #include +#if __STDC_VERSION__ < 202311L && !defined(thread_local) +# if BFS_USE_THREADS_H +# include +# else +# define thread_local _Thread_local +# endif +#endif + #define thread_verify(expr, cond) \ bfs_verify((errno = (expr), (cond)), "%s: %s", #expr, strerror(errno)) -- cgit v1.2.3