Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
#define Py_Is(x, y) ((x) == (y))

#if defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
PyAPI_FUNC(uintptr_t) _Py_GetThreadLocal_Addr(void);

static inline uintptr_t
_Py_ThreadId(void)
{
Expand Down Expand Up @@ -290,6 +292,13 @@ _Py_ThreadId(void)
// tp is Thread Pointer provided by the RISC-V ABI.
__asm__ ("mv %0, tp" : "=r" (tid));
#endif
#elif defined(thread_local) || defined(__GNUC__)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be an #else. We're not using thread_local or depending on GNU specific features here in object.h.

// gh-112535: Using characteristics of TLS address mapping.
// The address of the thread-local variable is not equal with the actual thread pointer,
// However, it has the property of being determined by loader at runtime, with no duplication of values
// between different threads. So it can be used as the similar role of __builtin_thread_pointer().
// But since it requires offset calculation, this hack is more expensive than __builtin_thread_pointer().
Comment thread
corona10 marked this conversation as resolved.
Outdated
tid = _Py_GetThreadLocal_Addr();
#else
# error "define _Py_ThreadId for this platform"
#endif
Expand Down
10 changes: 10 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,16 @@ _PyThreadState_Bind(PyThreadState *tstate)
}
}

#if defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
uintptr_t
_Py_GetThreadLocal_Addr(void) {
Comment thread
corona10 marked this conversation as resolved.
Outdated
#ifdef HAVE_THREAD_LOCAL
return (uintptr_t)&_Py_tss_tstate;
Comment thread
corona10 marked this conversation as resolved.
#else
# error "no supported thread-local variable storage classifier"
#endif
}
#endif

/***********************************/
/* routines for advanced debuggers */
Expand Down