From e54772b468e4ca7519a75467cb0a6710f587efb3 Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Sat, 8 Jun 2024 13:46:12 +0000 Subject: [PATCH] rts: replace ad-hoc MYTASK_USE_TLV with proper CC_SUPPORTS_TLS This patch replaces the ad-hoc `MYTASK_USE_TLV` with the `CC_SUPPORTS_TLS` macro. If TLS support is detected by autoconf, then we should use that for managing `myTask` in the threaded RTS. (cherry picked from commit f3017dd3a7e3a2bd8a4f0b9f86268ff403f8f7c6) --- rts/Task.c | 6 +++--- rts/Task.h | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rts/Task.c b/rts/Task.c index de24253db59..42ec6b273b8 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -52,7 +52,7 @@ Mutex all_tasks_mutex; // A thread-local-storage key that we can use to get access to the // current thread's Task structure. #if defined(THREADED_RTS) -# if defined(MYTASK_USE_TLV) +# if CC_SUPPORTS_TLS __thread Task *my_task; # else ThreadLocalKey currentTaskKey; @@ -75,7 +75,7 @@ initTaskManager (void) peakWorkerCount = 0; tasksInitialized = 1; #if defined(THREADED_RTS) -#if !defined(MYTASK_USE_TLV) +#if !CC_SUPPORTS_TLS newThreadLocalKey(¤tTaskKey); #endif initMutex(&all_tasks_mutex); @@ -109,7 +109,7 @@ freeTaskManager (void) #if defined(THREADED_RTS) closeMutex(&all_tasks_mutex); -#if !defined(MYTASK_USE_TLV) +#if !CC_SUPPORTS_TLS freeThreadLocalKey(¤tTaskKey); #endif #endif diff --git a/rts/Task.h b/rts/Task.h index 72dd980e68f..6c13d706f51 100644 --- a/rts/Task.h +++ b/rts/Task.h @@ -265,11 +265,7 @@ extern uint32_t peakWorkerCount; // A thread-local-storage key that we can use to get access to the // current thread's Task structure. #if defined(THREADED_RTS) -#if ((defined(linux_HOST_OS) && \ - (defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH))) || \ - (defined(mingw32_HOST_OS) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 4)) && \ - (!defined(CC_LLVM_BACKEND)) -#define MYTASK_USE_TLV +#if CC_SUPPORTS_TLS extern __thread Task *my_task; #else extern ThreadLocalKey currentTaskKey; @@ -287,7 +283,7 @@ extern Task *my_task; INLINE_HEADER Task * myTask (void) { -#if defined(THREADED_RTS) && !defined(MYTASK_USE_TLV) +#if defined(THREADED_RTS) && !CC_SUPPORTS_TLS return (Task*) getThreadLocalVar(¤tTaskKey); #else return my_task; @@ -297,7 +293,7 @@ myTask (void) INLINE_HEADER void setMyTask (Task *task) { -#if defined(THREADED_RTS) && !defined(MYTASK_USE_TLV) +#if defined(THREADED_RTS) && !CC_SUPPORTS_TLS setThreadLocalVar(¤tTaskKey,task); #else my_task = task; -- GitLab