mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
code review: make exiting thread safe
This commit is contained in:
parent
68f8ec6a2d
commit
cc959daa04
1 changed files with 2 additions and 6 deletions
|
|
@ -229,12 +229,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
|
|||
{
|
||||
ENSURE_Context(octx, -1)
|
||||
PyContext *ctx = (PyContext *)octx;
|
||||
#ifdef Py_GIL_DISABLED
|
||||
int already_entered = _Py_atomic_exchange_int(&ctx->ctx_entered, 0);
|
||||
#else
|
||||
int already_entered = ctx->ctx_entered;
|
||||
ctx->ctx_entered = 0;
|
||||
#endif
|
||||
int already_entered = FT_ATOMIC_LOAD_INT_RELAXED(ctx->ctx_entered);
|
||||
|
||||
if (!already_entered) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
|
|
@ -253,6 +248,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
|
|||
Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);
|
||||
|
||||
ctx->ctx_prev = NULL;
|
||||
FT_ATOMIC_STORE_INT(ctx->ctx_entered, 0);
|
||||
context_switched(ts);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue