From 4040ad259dceca1a3f66c0c2f2f11dda57360361 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 19 Dec 2018 23:10:37 +0000 Subject: [PATCH] Add compiler dependent macros for thread_local Also add stdc-predef.h because __STDC_NO_THREADS__ is defined there. Signed-off-by: Yuxuan Shui --- src/compiler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/compiler.h b/src/compiler.h index dca59e9..86ab76c 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -2,6 +2,8 @@ // Copyright (c) 2018 Yuxuan Shui #pragma once +#include + #define auto __auto_type #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) @@ -79,3 +81,13 @@ #else # define unreachable do {} while(0) #endif + +#ifndef __STDC_NO_THREADS__ +# include +#elif __STDC_VERSION__ >= 201112L +# define thread_local _Thread_local +#elif defined(__GNUC__) || defined(__clang__) +# define thread_local __thread +#else +# define thread_local _Pragma("GCC error \"No thread local storage support\"") __error__ +#endif