]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084)
authorFurkan Onder <furkanonder@protonmail.com>
Thu, 14 Dec 2023 23:42:33 +0000 (02:42 +0300)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 23:42:33 +0000 (08:42 +0900)
Update _Py_ThreadId() to support RISC-V

Include/object.h

index bd576b0bd43211cec478edd06584c23abcab357a..d22e5c2b8be2a9d19ee129d82d000eceb1eb90c3 100644 (file)
@@ -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