mirror of
https://github.com/python/cpython.git
synced 2026-04-15 00:00:57 +00:00
[3.14] gh-144981: Make PyUnstable_Code_SetExtra/GetExtra thread-safe (GH-144980) (#145052)
Co-authored-by: Alper <alperyoney@fb.com>
This commit is contained in:
parent
f42692838c
commit
7b3e6bde26
5 changed files with 250 additions and 31 deletions
|
|
@ -3486,11 +3486,27 @@ PyUnstable_Eval_RequestCodeExtraIndex(freefunc free)
|
|||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
Py_ssize_t new_index;
|
||||
|
||||
if (interp->co_extra_user_count == MAX_CO_EXTRA_USERS - 1) {
|
||||
#ifdef Py_GIL_DISABLED
|
||||
struct _py_code_state *state = &interp->code_state;
|
||||
FT_MUTEX_LOCK(&state->mutex);
|
||||
#endif
|
||||
|
||||
if (interp->co_extra_user_count >= MAX_CO_EXTRA_USERS - 1) {
|
||||
#ifdef Py_GIL_DISABLED
|
||||
FT_MUTEX_UNLOCK(&state->mutex);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
new_index = interp->co_extra_user_count++;
|
||||
|
||||
new_index = interp->co_extra_user_count;
|
||||
interp->co_extra_freefuncs[new_index] = free;
|
||||
|
||||
// Publish freefuncs[new_index] before making the index visible.
|
||||
FT_ATOMIC_STORE_SSIZE_RELEASE(interp->co_extra_user_count, new_index + 1);
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
FT_MUTEX_UNLOCK(&state->mutex);
|
||||
#endif
|
||||
return new_index;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue