From: Furkan Onder Date: Thu, 14 Dec 2023 23:42:33 +0000 (+0300) Subject: gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084) X-Git-Tag: v3.13.0a3~369 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f34e22c6470d1c5d0e2a3ffb2272d375c22654b9;p=thirdparty%2FPython%2Fcpython.git gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084) Update _Py_ThreadId() to support RISC-V --- diff --git a/Include/object.h b/Include/object.h index bd576b0bd432..d22e5c2b8be2 100644 --- a/Include/object.h +++ b/Include/object.h @@ -283,6 +283,13 @@ _Py_ThreadId(void) // Both GCC and Clang have supported __builtin_thread_pointer // for s390 from long time ago. tid = (uintptr_t)__builtin_thread_pointer(); +#elif defined(__riscv) + #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) + tid = (uintptr_t)__builtin_thread_pointer(); + #else + // tp is Thread Pointer provided by the RISC-V ABI. + __asm__ ("mv %0, tp" : "=r" (tid)); + #endif #else # error "define _Py_ThreadId for this platform" #endif