gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084)

Update _Py_ThreadId() to support RISC-V
This commit is contained in:
Furkan Onder 2023-12-15 02:42:33 +03:00 committed by GitHub
parent 5f7d7353b4
commit f34e22c647
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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