Skip to content

Commit 0e5d4ea

Browse files
committed
Fix C++ compatibility for TSRM_TLS
If a C++11 source is compiled, thread_local is preferred. Furthermore, at least GCC treats __thread vs. thread_local a different way and under certain circumstances would refuse to compile __thread is a C++11 source. This change is far behind in time, any up-to-date compiler supports C++11 and otherwise it won't take effect on lower versions.
1 parent 5b28218 commit 0e5d4ea

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

TSRM/TSRM.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,14 @@ TSRM_API void tsrm_free_interpreter_context(void *context);
157157
TSRM_API void *tsrm_get_ls_cache(void);
158158
TSRM_API uint8_t tsrm_is_main_thread(void);
159159

160-
#ifdef TSRM_WIN32
161-
# define TSRM_TLS __declspec(thread)
160+
#if defined(__cplusplus) && __cplusplus > 199711L
161+
# define TSRM_TLS thread_local
162162
#else
163-
# define TSRM_TLS __thread
163+
# ifdef TSRM_WIN32
164+
# define TSRM_TLS __declspec(thread)
165+
# else
166+
# define TSRM_TLS __thread
167+
# endif
164168
#endif
165169

166170
#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)

0 commit comments

Comments
 (0)