| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -64,27 +64,35 @@ _Py_ThreadCanHandlePendingCalls(void) | |
| /* Variable and macro for in-line access to current thread | ||
| and interpreter state */ | ||
|
|
||
| static inline PyThreadState* | ||
| _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime) | ||
| { | ||
| return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->tstate_current); | ||
| } | ||
| #if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE) | ||
| extern _Py_thread_local PyThreadState *_Py_tss_tstate; | ||
| #endif | ||
| PyAPI_DATA(PyThreadState *) _PyThreadState_GetCurrent(void); | ||
|
|
||
| /* Get the current Python thread state. | ||
|
|
||
| Efficient macro reading directly the 'tstate_current' atomic | ||
| variable. The macro is unsafe: it does not check for error and it can | ||
| return NULL. | ||
| This function is unsafe: it does not check for error and it can return NULL. | ||
|
|
||
| The caller must hold the GIL. | ||
|
|
||
| See also PyThreadState_Get() and _PyThreadState_UncheckedGet(). */ | ||
| static inline PyThreadState* | ||
| _PyThreadState_GET(void) | ||
| { | ||
| return _PyRuntimeState_GetThreadState(&_PyRuntime); | ||
| #if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE) | ||
| return _Py_tss_tstate; | ||
| #else | ||
| return _PyThreadState_GetCurrent(); | ||
| #endif | ||
| } | ||
|
|
||
| static inline PyThreadState* | ||
| _PyRuntimeState_GetThreadState(_PyRuntimeState *Py_UNUSED(runtime)) | ||
| { | ||
| return _PyThreadState_GET(); | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis function no longer makes sense: I wrote PR #104171 to remove it.
Sorry, something went wrong.
ericsnowcurrently reacted with thumbs up emoji
All reactions
|
||
| } | ||
|
|
||
|
|
||
| static inline void | ||
| _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate) | ||
| { | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -663,6 +663,27 @@ extern char * _getpty(int *, int, mode_t, int); | |
| # define WITH_THREAD | ||
| #endif | ||
|
|
||
| #ifdef WITH_THREAD | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis test is useless. This macro is now always defined. It's only kept for backward compatibility.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDoesn't it affect WASM builds?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySee the code 3 lines above: #ifndef WITH_THREAD
# define WITH_THREAD
#endif
Sorry, something went wrong.
ericsnowcurrently reacted with thumbs up emoji
All reactions
|
||
| # ifdef Py_BUILD_CORE | ||
| # ifdef HAVE_THREAD_LOCAL | ||
| # error "HAVE_THREAD_LOCAL is already defined" | ||
| # endif | ||
| # define HAVE_THREAD_LOCAL 1 | ||
| # ifdef thread_local | ||
| # define _Py_thread_local thread_local | ||
| # elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) | ||
| # define _Py_thread_local _Thread_local | ||
| # elif defined(_MSC_VER) /* AKA NT_THREADS */ | ||
| # define _Py_thread_local __declspec(thread) | ||
| # elif defined(__GNUC__) /* includes clang */ | ||
| # define _Py_thread_local __thread | ||
| # else | ||
| // fall back to the PyThread_tss_*() API, or ignore. | ||
| # undef HAVE_THREAD_LOCAL | ||
| # endif | ||
| # endif | ||
| #endif | ||
|
|
||
| /* Check that ALT_SOABI is consistent with Py_TRACE_REFS: | ||
| ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */ | ||
| #if defined(ALT_SOABI) && defined(Py_TRACE_REFS) | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| We've replaced our use of ``_PyRuntime.tstate_current`` with a thread-local | ||
| variable. This is a fairly low-level implementation detail, and there | ||
| should be no change in behavior. |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhat is the use case for this new _PyThreadState_GetCurrent() function? There is already PyThreadState_Get(). How is it different?
The API to get the current thread state is already complicated and has a complicated history: https://pythondev.readthedocs.io/pystate.html
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt's there because I couldn't find a way to mix PyAPI_DATA with _Py_thread_local. Looks like that's the same issue you ran into in 2020.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.