Skip to content

Commit f34e22c

Browse files
authored
gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084)
Update _Py_ThreadId() to support RISC-V
1 parent 5f7d735 commit f34e22c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Include/object.h

+7
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ _Py_ThreadId(void)
283283
// Both GCC and Clang have supported __builtin_thread_pointer
284284
// for s390 from long time ago.
285285
tid = (uintptr_t)__builtin_thread_pointer();
286+
#elif defined(__riscv)
287+
#if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer)
288+
tid = (uintptr_t)__builtin_thread_pointer();
289+
#else
290+
// tp is Thread Pointer provided by the RISC-V ABI.
291+
__asm__ ("mv %0, tp" : "=r" (tid));
292+
#endif
286293
#else
287294
# error "define _Py_ThreadId for this platform"
288295
#endif

0 commit comments

Comments
 (0)