mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-117323: Make cell thread-safe in free-threaded builds (#117330)
Use critical sections to lock around accesses to cell contents. The critical sections are no-ops in the default (with GIL) build.
This commit is contained in:
parent
397d88db5e
commit
19c1dd60c5
11 changed files with 83 additions and 43 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/* Cell object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "pycore_cell.h" // PyCell_GetRef()
|
||||
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
|
||||
#include "pycore_object.h"
|
||||
|
||||
|
|
@ -56,8 +57,7 @@ PyCell_Get(PyObject *op)
|
|||
PyErr_BadInternalCall();
|
||||
return NULL;
|
||||
}
|
||||
PyObject *value = PyCell_GET(op);
|
||||
return Py_XNewRef(value);
|
||||
return PyCell_GetRef((PyCellObject *)op);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -67,9 +67,7 @@ PyCell_Set(PyObject *op, PyObject *value)
|
|||
PyErr_BadInternalCall();
|
||||
return -1;
|
||||
}
|
||||
PyObject *old_value = PyCell_GET(op);
|
||||
PyCell_SET(op, Py_XNewRef(value));
|
||||
Py_XDECREF(old_value);
|
||||
PyCell_SetTakeRef((PyCellObject *)op, Py_XNewRef(value));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue