31 namespace base_internal {
33 #if ABSL_THREAD_IDENTITY_MODE != ABSL_THREAD_IDENTITY_MODE_USE_CPP11 37 pthread_key_t thread_identity_pthread_key;
38 std::atomic<bool> pthread_key_initialized(
false);
41 pthread_key_create(&thread_identity_pthread_key, reclaimer);
42 pthread_key_initialized.store(
true, std::memory_order_release);
47 #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \ 48 ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11 56 __attribute__((visibility(
"protected")))
59 #endif // TLS or CPP11 67 #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC 69 absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
76 pthread_setspecific(thread_identity_pthread_key,
77 reinterpret_cast<void*>(identity));
86 sigset_t curr_signals;
87 sigfillset(&all_signals);
88 pthread_sigmask(SIG_SETMASK, &all_signals, &curr_signals);
89 pthread_setspecific(thread_identity_pthread_key,
90 reinterpret_cast<void*>(identity));
91 pthread_sigmask(SIG_SETMASK, &curr_signals,
nullptr);
92 #endif // !__EMSCRIPTEN__ 94 #elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS 96 absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
98 pthread_setspecific(thread_identity_pthread_key,
99 reinterpret_cast<void*>(identity));
100 thread_identity_ptr = identity;
101 #elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11 102 thread_local std::unique_ptr<ThreadIdentity, ThreadIdentityReclaimerFunction>
103 holder(identity, reclaimer);
104 thread_identity_ptr = identity;
106 #error Unimplemented ABSL_THREAD_IDENTITY_MODE 111 #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \ 112 ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11 113 thread_identity_ptr =
nullptr;
114 #elif ABSL_THREAD_IDENTITY_MODE == \ 115 ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC 121 #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC 123 bool initialized = pthread_key_initialized.load(std::memory_order_acquire);
128 pthread_getspecific(thread_identity_pthread_key));
ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity * thread_identity_ptr
void(*)(void *) ThreadIdentityReclaimerFunction
ThreadIdentity * CurrentThreadIdentityIfPresent()
void call_once(absl::once_flag &flag, Callable &&fn, Args &&...args)
void SetCurrentThreadIdentity(ThreadIdentity *identity, ThreadIdentityReclaimerFunction reclaimer)
void ClearCurrentThreadIdentity()
#define ABSL_PER_THREAD_TLS_KEYWORD