Skip to content

Commit

Permalink
gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084)
Browse files Browse the repository at this point in the history
Update _Py_ThreadId() to support RISC-V
  • Loading branch information
furkanonder authored Dec 14, 2023
1 parent 5f7d735 commit f34e22c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f34e22c

Please sign in to comment.