diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2024-12-16 19:31:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 19:31:44 (GMT) |
commit | 3b766824fe59030100964752be0556084d4461af (patch) | |
tree | 5986d46e9e7a744bb6581b218539f60168ff6ef6 /Include | |
parent | 4937ba54c0ff7cc4a83d7345d398b804365af2d6 (diff) | |
download | cpython-3b766824fe59030100964752be0556084d4461af.zip cpython-3b766824fe59030100964752be0556084d4461af.tar.gz cpython-3b766824fe59030100964752be0556084d4461af.tar.bz2 |
gh-126907: make `atexit` thread safe in free-threading (#127935)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_atexit.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Include/internal/pycore_atexit.h b/Include/internal/pycore_atexit.h index cde5b53..db1e556 100644 --- a/Include/internal/pycore_atexit.h +++ b/Include/internal/pycore_atexit.h @@ -36,23 +36,29 @@ typedef struct atexit_callback { struct atexit_callback *next; } atexit_callback; -typedef struct { - PyObject *func; - PyObject *args; - PyObject *kwargs; -} atexit_py_callback; - struct atexit_state { +#ifdef Py_GIL_DISABLED + PyMutex ll_callbacks_lock; +#endif atexit_callback *ll_callbacks; // XXX The rest of the state could be moved to the atexit module state // and a low-level callback added for it during module exec. // For the moment we leave it here. - atexit_py_callback **callbacks; - int ncallbacks; - int callback_len; + + // List containing tuples with callback information. + // e.g. [(func, args, kwargs), ...] + PyObject *callbacks; }; +#ifdef Py_GIL_DISABLED +# define _PyAtExit_LockCallbacks(state) PyMutex_Lock(&state->ll_callbacks_lock); +# define _PyAtExit_UnlockCallbacks(state) PyMutex_Unlock(&state->ll_callbacks_lock); +#else +# define _PyAtExit_LockCallbacks(state) +# define _PyAtExit_UnlockCallbacks(state) +#endif + // Export for '_interpchannels' shared extension PyAPI_FUNC(int) _Py_AtExit( PyInterpreterState *interp, |