[Git][ghc/ghc][wip/no-cc-supports-tls] rts: remove obsolete CC_SUPPORTS_TLS logic
Cheng Shao pushed to branch wip/no-cc-supports-tls at Glasgow Haskell Compiler / GHC Commits: ead887c5 by Cheng Shao at 2025-09-17T00:18:14+02:00 rts: remove obsolete CC_SUPPORTS_TLS logic This patch removes obsolete CC_SUPPORTS_TLS logic throughout the rts, given __thread is now uniformly supported by C toolchains of all platforms we currently support. - - - - - 9 changed files: - rts/Task.c - rts/Task.h - rts/configure.ac - rts/include/rts/OSThreads.h - rts/posix/OSThreads.c - rts/sm/GCTDecl.h - rts/sm/GCThread.h - rts/sm/Storage.c - rts/win32/OSThreads.c Changes: ===================================== rts/Task.c ===================================== @@ -52,11 +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 CC_SUPPORTS_TLS __thread Task *my_task; -# else -ThreadLocalKey currentTaskKey; -# endif #else Task *my_task; #endif @@ -75,9 +71,6 @@ initTaskManager (void) peakWorkerCount = 0; tasksInitialized = 1; #if defined(THREADED_RTS) -#if !CC_SUPPORTS_TLS - newThreadLocalKey(¤tTaskKey); -#endif initMutex(&all_tasks_mutex); #endif } @@ -109,9 +102,6 @@ freeTaskManager (void) #if defined(THREADED_RTS) closeMutex(&all_tasks_mutex); -#if !CC_SUPPORTS_TLS - freeThreadLocalKey(¤tTaskKey); -#endif #endif tasksInitialized = 0; ===================================== rts/Task.h ===================================== @@ -265,12 +265,8 @@ 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 CC_SUPPORTS_TLS extern __thread Task *my_task; #else -extern ThreadLocalKey currentTaskKey; -#endif -#else extern Task *my_task; #endif @@ -283,21 +279,13 @@ extern Task *my_task; INLINE_HEADER Task * myTask (void) { -#if defined(THREADED_RTS) && !CC_SUPPORTS_TLS - return (Task*) getThreadLocalVar(¤tTaskKey); -#else return my_task; -#endif } INLINE_HEADER void setMyTask (Task *task) { -#if defined(THREADED_RTS) && !CC_SUPPORTS_TLS - setThreadLocalVar(¤tTaskKey,task); -#else my_task = task; -#endif } // Tasks are identified by their OS thread ID, which can be serialised ===================================== rts/configure.ac ===================================== @@ -234,19 +234,6 @@ AC_CHECK_FUNCS([eventfd]) AC_CHECK_FUNCS([getpid getuid raise]) -dnl ** Check for __thread support in the compiler -AC_MSG_CHECKING(for __thread support) -AC_COMPILE_IFELSE( - [ AC_LANG_SOURCE([[__thread int tester = 0;]]) ], - [ - AC_MSG_RESULT(yes) - AC_DEFINE([CC_SUPPORTS_TLS],[1],[Define to 1 if __thread is supported]) - ], - [ - AC_MSG_RESULT(no) - AC_DEFINE([CC_SUPPORTS_TLS],[0],[Define to 1 if __thread is supported]) - ]) - dnl large address space support (see rts/include/rts/storage/MBlock.h) dnl dnl Darwin has vm_allocate/vm_protect ===================================== rts/include/rts/OSThreads.h ===================================== @@ -40,7 +40,6 @@ typedef struct { } Condition; typedef pthread_mutex_t Mutex; typedef pthread_t OSThreadId; -typedef pthread_key_t ThreadLocalKey; #define OSThreadProcAttr /* nothing */ @@ -107,7 +106,6 @@ typedef CONDITION_VARIABLE Condition; typedef DWORD OSThreadId; // don't be tempted to use HANDLE as the OSThreadId: there can be // many HANDLES to a given thread, so comparison would not work. -typedef DWORD ThreadLocalKey; #define OSThreadProcAttr @@ -168,7 +166,6 @@ typedef SRWLOCK Mutex; typedef void* Condition; typedef void* Mutex; typedef void* OSThreadId; -typedef void* ThreadLocalKey; #define OSThreadProcAttr @@ -216,14 +213,6 @@ extern bool timedWaitCondition ( Condition* pCond, Mutex* pMut, Time timeout) extern void initMutex ( Mutex* pMut ); extern void closeMutex ( Mutex* pMut ); -// -// Thread-local storage -// -void newThreadLocalKey (ThreadLocalKey *key); -void *getThreadLocalVar (ThreadLocalKey *key); -void setThreadLocalVar (ThreadLocalKey *key, void *value); -void freeThreadLocalKey (ThreadLocalKey *key); - // Processors and affinity void setThreadAffinity (uint32_t n, uint32_t m); void setThreadNode (uint32_t node); ===================================== rts/posix/OSThreads.c ===================================== @@ -286,43 +286,6 @@ closeMutex(Mutex* pMut) pthread_mutex_destroy(pMut); } -void -newThreadLocalKey (ThreadLocalKey *key) -{ - int r; - if ((r = pthread_key_create(key, NULL)) != 0) { - barf("newThreadLocalKey: %s", strerror(r)); - } -} - -void * -getThreadLocalVar (ThreadLocalKey *key) -{ - return pthread_getspecific(*key); - // Note: a return value of NULL can indicate that either the key - // is not valid, or the key is valid and the data value has not - // yet been set. We need to use the latter case, so we cannot - // detect errors here. -} - -void -setThreadLocalVar (ThreadLocalKey *key, void *value) -{ - int r; - if ((r = pthread_setspecific(*key,value)) != 0) { - barf("setThreadLocalVar: %s", strerror(r)); - } -} - -void -freeThreadLocalKey (ThreadLocalKey *key) -{ - int r; - if ((r = pthread_key_delete(*key)) != 0) { - barf("freeThreadLocalKey: %s", strerror(r)); - } -} - #if defined(THREADED_RTS) static void * ===================================== rts/sm/GCTDecl.h ===================================== @@ -50,23 +50,10 @@ extern StgWord8 the_gc_thread[]; /* -------------------------------------------------------------------------- */ -/* Now, llvm-gcc and some older Clang compilers do not support - __thread. So we have to fallback to the extremely slow case, - unfortunately. - - Also, the iOS Clang compiler doesn't support __thread either for - some bizarre reason, so there's not much we can do about that... */ -#if defined(CC_LLVM_BACKEND) && (CC_SUPPORTS_TLS == 0) -#define gct ((gc_thread *)(pthread_getspecific(gctKey))) -#define SET_GCT(to) (pthread_setspecific(gctKey, to)) -#define DECLARE_GCT ThreadLocalKey gctKey; - -/* -------------------------------------------------------------------------- */ - -/* However, if we *are* using an LLVM based compiler with __thread +/* If we *are* using an LLVM based compiler with __thread support, then use that (since LLVM doesn't support global register variables.) */ -#elif defined(CC_LLVM_BACKEND) && (CC_SUPPORTS_TLS == 1) +#if defined(CC_LLVM_BACKEND) extern __thread gc_thread* gct; #define SET_GCT(to) gct = (to) #define DECLARE_GCT __thread gc_thread* gct; @@ -107,16 +94,11 @@ GCT_REG_DECL(gc_thread*, gct, REG_R1); /* Finally, as an absolute fallback, if none of the above tests check out but we *do* have __thread support, then use that. */ -#elif CC_SUPPORTS_TLS == 1 +#else extern __thread gc_thread* gct; #define SET_GCT(to) gct = (to) #define DECLARE_GCT __thread gc_thread* gct; -/* -------------------------------------------------------------------------- */ - -/* Impossible! */ -#else -#error Cannot find a way to declare the thread-local gc variable! #endif #endif // THREADED_RTS ===================================== rts/sm/GCThread.h ===================================== @@ -212,8 +212,4 @@ extern uint32_t n_gc_threads; extern gc_thread **gc_threads; -#if defined(THREADED_RTS) && defined(CC_LLVM_BACKEND) -extern ThreadLocalKey gctKey; -#endif - #include "EndPrivate.h" ===================================== rts/sm/Storage.c ===================================== @@ -326,10 +326,6 @@ void storageAddCapabilities (uint32_t from, uint32_t to) } } -#if defined(THREADED_RTS) && defined(CC_LLVM_BACKEND) && (CC_SUPPORTS_TLS == 0) - newThreadLocalKey(&gctKey); -#endif - initGcThreads(from, to); } @@ -351,9 +347,6 @@ freeStorage (bool free_heap) closeMutex(&sm_mutex); #endif stgFree(nurseries); -#if defined(THREADED_RTS) && defined(CC_LLVM_BACKEND) && (CC_SUPPORTS_TLS == 0) - freeThreadLocalKey(&gctKey); -#endif freeGcThreads(); } ===================================== rts/win32/OSThreads.c ===================================== @@ -87,56 +87,6 @@ osThreadIsAlive(OSThreadId id) return (exit_code == STILL_ACTIVE); } -void -newThreadLocalKey (ThreadLocalKey *key) -{ - DWORD r; - r = TlsAlloc(); - if (r == TLS_OUT_OF_INDEXES) { - barf("newThreadLocalKey: out of keys"); - } - *key = r; -} - -void * -getThreadLocalVar (ThreadLocalKey *key) -{ - void *r; - r = TlsGetValue(*key); -#if defined(DEBUG) - // r is allowed to be NULL - it can mean that either there was an - // error or the stored value is in fact NULL. - if (GetLastError() != NO_ERROR) { - sysErrorBelch("getThreadLocalVar"); - stg_exit(EXIT_FAILURE); - } -#endif - return r; -} - -void -setThreadLocalVar (ThreadLocalKey *key, void *value) -{ - BOOL b; - b = TlsSetValue(*key, value); - if (!b) { - sysErrorBelch("setThreadLocalVar"); - stg_exit(EXIT_FAILURE); - } -} - -void -freeThreadLocalKey (ThreadLocalKey *key) -{ - BOOL r; - r = TlsFree(*key); - if (r == 0) { - DWORD dw = GetLastError(); - barf("freeThreadLocalKey failed: %lu", dw); - } -} - - static unsigned forkOS_createThreadWrapper ( void * entry ) { View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ead887c5da81ed333f6862e477559002... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ead887c5da81ed333f6862e477559002... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Cheng Shao (@TerrorJack)