c11: Implement thread_local in c11/threads.h

Use thread_local when possible

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15087>
This commit is contained in:
Yonggang Luo
2022-04-09 22:33:44 +08:00
committed by Marge Bot
parent 09cd5c9bdb
commit 6e33ef2bb9
4 changed files with 33 additions and 7 deletions
+26
View File
@@ -26,6 +26,32 @@
/*---------------------------- macros ---------------------------*/
#ifndef _Thread_local
# if defined(__cplusplus)
/* C++11 doesn't need `_Thread_local` keyword or macro */
# elif !defined(__STDC_NO_THREADS__)
/* threads are optional in C11, _Thread_local present in this condition */
# elif defined(_MSC_VER)
# define _Thread_local __declspec(thread)
# elif defined(__GNUC__)
# define _Thread_local __thread
# else
/* Leave _Thread_local undefined so that use of _Thread_local would not promote
* to a non-thread-local global variable
*/
# endif
#endif
#if !defined(__cplusplus)
/*
* C11 thread_local() macro
* C++11 and above already have thread_local keyword
*/
# ifndef thread_local
# define thread_local _Thread_local
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif