diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2017-01-20 00:22:57 +0300 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2017-01-20 00:22:57 +0300 |
commit | 0893676f65845428cce02e71871b34ad7b676fd8 (patch) | |
tree | f3a35b5e2e2e40e541d3da0aaa5eb33372eb0a6b | |
parent | 6eedad45bcb621c6d26aafa4ec47d37cdbc1204e (diff) |
Enable workaround for build tools that don't support thread_local
Apple started to support thread_local in xcode starting from version 8.0,
this workaround enables the thread shutdown detection to compile even on
devices that don't have the latest xcode.
-rw-r--r-- | src/Native/Runtime/startup.cpp | 5 | ||||
-rw-r--r-- | src/Native/Runtime/unix/PalRedhawkUnix.cpp | 15 | ||||
-rw-r--r-- | src/Native/Runtime/unix/config.h.in | 2 | ||||
-rw-r--r-- | src/Native/Runtime/unix/configure.cmake | 9 |
4 files changed, 31 insertions, 0 deletions
diff --git a/src/Native/Runtime/startup.cpp b/src/Native/Runtime/startup.cpp index 8a7b0c56c..3a368191b 100644 --- a/src/Native/Runtime/startup.cpp +++ b/src/Native/Runtime/startup.cpp @@ -268,8 +268,13 @@ void __stdcall RuntimeThreadShutdown(void* thread) // that is made for the single thread that runs the final stages of orderly process // shutdown (i.e., the thread that delivers the DLL_PROCESS_DETACH notifications when the // process is being torn down via an ExitProcess call). +#if HAVE_THREAD_LOCAL + // If the current Unix platform doesn't support thread_local, we don't get the thread pointer + // as the parameter, we just get NULL, so we can check the thread validity only if the + // thread_local is supported UNREFERENCED_PARAMETER(thread); ASSERT((Thread*)thread == ThreadStore::GetCurrentThread()); +#endif if (!g_processShutdownHasStarted) { diff --git a/src/Native/Runtime/unix/PalRedhawkUnix.cpp b/src/Native/Runtime/unix/PalRedhawkUnix.cpp index 47df6e2d9..c9f8ea4a8 100644 --- a/src/Native/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/Native/Runtime/unix/PalRedhawkUnix.cpp @@ -410,6 +410,11 @@ public: typedef UnixHandle<UnixHandleType::Thread, pthread_t> ThreadUnixHandle; +#if !HAVE_THREAD_LOCAL +extern "C" int __cxa_thread_atexit(void (*)(void*), void*, void *); +extern "C" void *__dso_handle; +#endif + // The Redhawk PAL must be initialized before any of its exports can be called. Returns true for a successful // initialization and false on failure. REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit() @@ -438,6 +443,10 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit() } #endif // !USE_PORTABLE_HELPERS +#if !HAVE_THREAD_LOCAL + __cxa_thread_atexit(RuntimeThreadShutdown, NULL, &__dso_handle); +#endif + return true; } @@ -447,6 +456,8 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalHasCapability(PalCapability capability) return (g_dwPALCapabilities & (uint32_t)capability) == (uint32_t)capability; } +#if HAVE_THREAD_LOCAL + struct TlsDestructionMonitor { void* m_thread = nullptr; @@ -469,6 +480,8 @@ struct TlsDestructionMonitor // is called when a thread is being shut down. thread_local TlsDestructionMonitor tls_destructionMonitor; +#endif // HAVE_THREAD_LOCAL + // Attach thread to PAL. // It can be called multiple times for the same thread. // It fails fast if a different thread was already registered. @@ -476,7 +489,9 @@ thread_local TlsDestructionMonitor tls_destructionMonitor; // thread - thread to attach extern "C" void PalAttachThread(void* thread) { +#if HAVE_THREAD_LOCAL tls_destructionMonitor.SetThread(thread); +#endif } // Detach thread from PAL. diff --git a/src/Native/Runtime/unix/config.h.in b/src/Native/Runtime/unix/config.h.in index 085ceaa3a..ca5f5aa71 100644 --- a/src/Native/Runtime/unix/config.h.in +++ b/src/Native/Runtime/unix/config.h.in @@ -29,4 +29,6 @@ #cmakedefine01 HAVE_CLOCK_MONOTONIC_COARSE #cmakedefine01 HAVE_MACH_ABSOLUTE_TIME +#cmakedefine01 HAVE_THREAD_LOCAL + #endif diff --git a/src/Native/Runtime/unix/configure.cmake b/src/Native/Runtime/unix/configure.cmake index d58e1219e..a8fd29d18 100644 --- a/src/Native/Runtime/unix/configure.cmake +++ b/src/Native/Runtime/unix/configure.cmake @@ -105,4 +105,13 @@ int main() exit(ret); }" HAVE_MACH_ABSOLUTE_TIME) +check_cxx_source_compiles(" +thread_local int x; + +int main(int argc, char **argv) +{ + x = 1; + return 0; +}" HAVE_THREAD_LOCAL) + configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) |