Skip to content

Commit 08cfacd

Browse files
author
Thananon Patinyasakdikul
authored
Merge pull request #5272 from thananon/opal__thread
opal/threads: Added keyword `opal_thread_local` for TLS
2 parents 009a3f0 + 469a404 commit 08cfacd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

config/opal_setup_cc.m4

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ AC_DEFUN([OPAL_PROG_CC_C11_HELPER],[
4646
opal_prog_cc_c11_helper_CFLAGS_save=$CFLAGS
4747
CFLAGS="$CFLAGS $1"
4848

49-
OPAL_CC_HELPER([if $CC $1 supports C11 thread local storage], [opal_prog_cc_c11_helper__Thread_local_available],
49+
OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
5050
[],[[static _Thread_local int foo = 1;++foo;]], [OPAL_C_HAVE__THREAD_LOCAL],
5151
[Whether C compiler supports __Thread_local])
5252

@@ -160,6 +160,13 @@ AC_DEFUN([OPAL_SETUP_CC],[
160160
OPAL_PROG_CC_C11_HELPER([],[],[])
161161
fi
162162

163+
# Check if compiler support __thread
164+
OPAL_VAR_SCOPE_PUSH([opal_prog_cc__thread_available])
165+
OPAL_CC_HELPER([if $CC $1 supports __thread], [opal_prog_cc__thread_available],
166+
[],[[static __thread int foo = 1;++foo;]], [OPAL_C_HAVE___THREAD],
167+
[Whether C compiler supports __thread])
168+
OPAL_VAR_SCOPE_POP
169+
163170
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
164171

165172
# Check for standard headers, needed here because needed before

opal/threads/thread_usage.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,18 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64)
249249

250250
#endif
251251

252+
/* thread local storage */
253+
#if OPAL_C_HAVE__THREAD_LOCAL
254+
#define opal_thread_local _Thread_local
255+
#define OPAL_HAVE_THREAD_LOCAL 1
256+
257+
#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */
258+
#define opal_thread_local __thread
259+
#define OPAL_HAVE_THREAD_LOCAL 1
260+
#endif /* OPAL_C_HAVE___THREAD */
261+
262+
#if !defined(OPAL_HAVE_THREAD_LOCAL)
263+
#define OPAL_HAVE_THREAD_LOCAL 0
264+
#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */
265+
252266
#endif /* !defined(OPAL_THREAD_USAGE_H) */

0 commit comments

Comments
 (0)