Add compiler dependent macros for thread_local

Also add stdc-predef.h because __STDC_NO_THREADS__ is defined there.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-19 23:10:37 +00:00
parent e19e78d974
commit 4040ad259d
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,8 @@
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
#pragma once
#include <stdc-predef.h>
#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 <threads.h>
#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