gh-137514: Add a free-threading wrapper for mutexes (GH-137515)

Add `FT_MUTEX_LOCK`/`FT_MUTEX_UNLOCK`, which call `PyMutex_Lock` and `PyMutex_Unlock` on the free-threaded build, and no-op otherwise.
This commit is contained in:
Peter Bierma 2025-08-07 11:24:50 -04:00 committed by GitHub
parent dec624e0af
commit 082f370cdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 44 additions and 88 deletions

View file

@ -1689,9 +1689,7 @@ PyThreadState_Clear(PyThreadState *tstate)
"PyThreadState_Clear: warning: thread still has a generator\n");
}
#ifdef Py_GIL_DISABLED
PyMutex_Lock(&_PyRuntime.ceval.sys_trace_profile_mutex);
#endif
FT_MUTEX_LOCK(&_PyRuntime.ceval.sys_trace_profile_mutex);
if (tstate->c_profilefunc != NULL) {
tstate->interp->sys_profiling_threads--;
@ -1702,9 +1700,7 @@ PyThreadState_Clear(PyThreadState *tstate)
tstate->c_tracefunc = NULL;
}
#ifdef Py_GIL_DISABLED
PyMutex_Unlock(&_PyRuntime.ceval.sys_trace_profile_mutex);
#endif
FT_MUTEX_UNLOCK(&_PyRuntime.ceval.sys_trace_profile_mutex);
Py_CLEAR(tstate->c_profileobj);
Py_CLEAR(tstate->c_traceobj);