Skip to content

Use _Thread_local for thread-local storage #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ option(USE_GOLD_LINKER "use the gold linker" ${USE_GOLD_LINKER_DEFAULT})

option(USE_LLD_LINKER "use the lld linker" OFF)

option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via __thread" ON)
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via _Thread_local" ON)
set(DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE})

if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
Expand Down
2 changes: 1 addition & 1 deletion cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Define if building pthread work queues from source */
#cmakedefine01 DISPATCH_USE_INTERNAL_WORKQUEUE

/* Enable usage of thread local storage via __thread */
/* Enable usage of thread local storage via _Thread_local */
#cmakedefine01 DISPATCH_USE_THREAD_LOCAL_STORAGE

/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void (*_dispatch_end_NSAutoReleasePool)(void *);
#endif

#if DISPATCH_USE_THREAD_LOCAL_STORAGE
__thread struct dispatch_tsd __dispatch_tsd;
_Thread_local struct dispatch_tsd __dispatch_tsd;
#if defined(_WIN32)
DWORD __dispatch_tsd_key;
#else
Expand Down
4 changes: 2 additions & 2 deletions src/shims/tsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ _dispatch_thread_key_create(DWORD *k, void (DISPATCH_TSD_DTOR_CC *d)(void *))
dispatch_assert_zero((*k = FlsAlloc(d)));
}

extern __declspec(thread) struct dispatch_tsd __dispatch_tsd;
extern DWORD __dispatch_tsd_key;

#else
Expand All @@ -127,7 +126,6 @@ _dispatch_thread_key_create(pthread_key_t *k, void (DISPATCH_TSD_DTOR_CC *d)(voi
dispatch_assert_zero(pthread_key_create(k, d));
}

extern __thread struct dispatch_tsd __dispatch_tsd;
extern pthread_key_t __dispatch_tsd_key;

#endif
Expand Down Expand Up @@ -156,6 +154,8 @@ struct dispatch_tsd {
void *dispatch_deferred_items_key;
};

extern _Thread_local struct dispatch_tsd __dispatch_tsd;

extern void libdispatch_tsd_init(void);
extern void _libdispatch_tsd_cleanup(void *ctx);

Expand Down