Export of internal Abseil changes

--
cbd86b318ce206d1fe9eb001979b8d2efe57e5fa by Derek Mauro <dmauro@google.com>:

Stop inlining `CurrentThreadIdentityIfPresent()` on Apple platforms

In some build configurations the Apple linker rejects thread_local
variables exposed in headers

Fixes #954
Fixes #965

PiperOrigin-RevId: 375930997
GitOrigin-RevId: e34600e09f748b686d20a4f729ae914ebfd9e7bf
Change-Id: I9fcd2f02bd6abdea3ed412217e1be18f2c7bf762
pull/969/head
Abseil Team 4 years ago committed by Dino Radaković
parent 18045c4e32
commit 0d5156018d
  1. 8
      absl/base/internal/thread_identity.cc
  2. 17
      absl/base/internal/thread_identity.h

@ -120,10 +120,10 @@ void SetCurrentThreadIdentity(
ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
// Please see the comment on `CurrentThreadIdentityIfPresent` in
// thread_identity.h. Because DLLs cannot expose thread_local variables in
// headers, we opt for the correct-but-slower option of placing the definition
// of this function only in a translation unit inside DLL.
#if defined(ABSL_BUILD_DLL) || defined(ABSL_CONSUME_DLL)
// thread_identity.h. When we cannot expose thread_local variables in
// headers, we opt for the correct-but-slower option of not inlining this
// function.
#ifndef ABSL_INTERNAL_INLINE_CURRENT_THREAD_IDENTITY_IF_PRESENT
ThreadIdentity* CurrentThreadIdentityIfPresent() { return thread_identity_ptr; }
#endif
#endif

@ -236,13 +236,18 @@ ABSL_CONST_INIT extern thread_local ThreadIdentity* thread_identity_ptr;
#error Thread-local storage not detected on this platform
#endif
// thread_local variables cannot be in headers exposed by DLLs. However, it is
// important for performance reasons in general that
// `CurrentThreadIdentityIfPresent` be inlined. This is not possible across a
// DLL boundary so, with DLLs, we opt to have the function not be inlined. Note
// thread_local variables cannot be in headers exposed by DLLs or in certain
// build configurations on Apple platforms. However, it is important for
// performance reasons in general that `CurrentThreadIdentityIfPresent` be
// inlined. In the other cases we opt to have the function not be inlined. Note
// that `CurrentThreadIdentityIfPresent` is declared above so we can exclude
// this entire inline definition when compiling as a DLL.
#if !defined(ABSL_BUILD_DLL) && !defined(ABSL_CONSUME_DLL)
// this entire inline definition.
#if !defined(__APPLE__) && !defined(ABSL_BUILD_DLL) && \
!defined(ABSL_CONSUME_DLL)
#define ABSL_INTERNAL_INLINE_CURRENT_THREAD_IDENTITY_IF_PRESENT 1
#endif
#ifdef ABSL_INTERNAL_INLINE_CURRENT_THREAD_IDENTITY_IF_PRESENT
inline ThreadIdentity* CurrentThreadIdentityIfPresent() {
return thread_identity_ptr;
}

Loading…
Cancel
Save