Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add _GET_OWN_GIL().
  • Loading branch information
ericsnowcurrently committed Sep 12, 2022
commit 3ce9695374dd2dce25ab66121c4460016cd3db3e
26 changes: 14 additions & 12 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ is_tstate_valid(PyThreadState *tstate)
} \


/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
#define _GET_OWN_GIL(interp) \
(_Py_IsMainInterpreter(interp) ? (&_PyRuntime.ceval.gil) : NULL)

static inline struct _gil_state *
_get_gil(PyInterpreterState *interp)
{
Expand Down Expand Up @@ -493,14 +499,12 @@ PyEval_ThreadsInitialized(void)
PyStatus
_PyEval_InitGIL(PyThreadState *tstate)
{
if (!_Py_IsMainInterpreter(tstate->interp)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
struct _gil_state *gil = _get_gil(tstate->interp);
if (gil != _GET_OWN_GIL(tstate->interp)) {
/* It's a shared GIL. */
assert(!_Py_IsMainInterpreter(tstate->interp));
return _PyStatus_OK();
}

struct _gil_state *gil = _get_gil(tstate->interp);
assert(!gil_created(gil));

PyThread_init_thread();
Expand All @@ -515,14 +519,12 @@ _PyEval_InitGIL(PyThreadState *tstate)
void
_PyEval_FiniGIL(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
struct _gil_state *gil = _get_gil(interp);
if (gil != _GET_OWN_GIL(interp)) {
/* It's a shared GIL. */
assert(!_Py_IsMainInterpreter(interp));
return;
}

struct _gil_state *gil = _get_gil(interp);
if (!gil_created(gil)) {
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
yet: do nothing. */
Expand Down