-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Use critical sections to lock around accesses to cell contents. The critical sections are no-ops in the default (with GIL) build.
- Loading branch information
Showing
11 changed files
with
83 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef Py_INTERNAL_CELL_H | ||
#define Py_INTERNAL_CELL_H | ||
|
||
#include "pycore_critical_section.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
// Sets the cell contents to `value` and return previous contents. Steals a | ||
// reference to `value`. | ||
static inline PyObject * | ||
PyCell_SwapTakeRef(PyCellObject *cell, PyObject *value) | ||
{ | ||
PyObject *old_value; | ||
Py_BEGIN_CRITICAL_SECTION(cell); | ||
old_value = cell->ob_ref; | ||
cell->ob_ref = value; | ||
Py_END_CRITICAL_SECTION(); | ||
return old_value; | ||
} | ||
|
||
static inline void | ||
PyCell_SetTakeRef(PyCellObject *cell, PyObject *value) | ||
{ | ||
PyObject *old_value = PyCell_SwapTakeRef(cell, value); | ||
Py_XDECREF(old_value); | ||
} | ||
|
||
// Gets the cell contents. Returns a new reference. | ||
static inline PyObject * | ||
PyCell_GetRef(PyCellObject *cell) | ||
{ | ||
PyObject *res; | ||
Py_BEGIN_CRITICAL_SECTION(cell); | ||
res = Py_XNewRef(cell->ob_ref); | ||
Py_END_CRITICAL_SECTION(); | ||
return res; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_CELL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters