Skip to content

gh-99113: A Per-Interpreter GIL! #104209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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
_gil_runtime_state -> _gil_state.
  • Loading branch information
ericsnowcurrently committed Sep 12, 2022
commit e55fbdd15b651f3fbef05c630220f624d30edcd8
2 changes: 1 addition & 1 deletion Include/internal/pycore_gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {
#define FORCE_SWITCHING

/* ** The GIL ** */
struct _gil_runtime_state {
struct _gil_state {
/* microseconds (the Python API uses seconds, though) */
unsigned long interval;
/* Last PyThreadState holding / having held the GIL. This helps us
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {
#include "pycore_exceptions.h" // struct _Py_exc_state
#include "pycore_floatobject.h" // struct _Py_float_state
#include "pycore_genobject.h" // struct _Py_async_gen_state
#include "pycore_gil.h" // struct _gil_state
#include "pycore_gc.h" // struct _gc_runtime_state
#include "pycore_list.h" // struct _Py_list_state
#include "pycore_tuple.h" // struct _Py_tuple_state
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#endif

#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_gil.h" // struct _gil_runtime_state
#include "pycore_gil.h" // struct _gil_state
#include "pycore_global_objects.h" // struct _Py_global_objects
#include "pycore_interp.h" // PyInterpreterState
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
Expand All @@ -26,7 +26,7 @@ struct _ceval_runtime_state {
the main thread of the main interpreter can handle signals: see
_Py_ThreadCanHandleSignals(). */
_Py_atomic_int signals_pending;
struct _gil_runtime_state gil;
struct _gil_state gil;
};

/* GIL state */
Expand Down
24 changes: 12 additions & 12 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ is_tstate_valid(PyThreadState *tstate)

#define DEFAULT_INTERVAL 5000

static void _gil_initialize(struct _gil_runtime_state *gil)
static void _gil_initialize(struct _gil_state *gil)
{
_Py_atomic_int uninitialized = {-1};
gil->locked = uninitialized;
gil->interval = DEFAULT_INTERVAL;
}

static int gil_created(struct _gil_runtime_state *gil)
static int gil_created(struct _gil_state *gil)
{
return (_Py_atomic_load_explicit(&gil->locked, _Py_memory_order_acquire) >= 0);
}

static void create_gil(struct _gil_runtime_state *gil)
static void create_gil(struct _gil_state *gil)
{
MUTEX_INIT(gil->mutex);
#ifdef FORCE_SWITCHING
Expand All @@ -245,7 +245,7 @@ static void create_gil(struct _gil_runtime_state *gil)
_Py_atomic_store_explicit(&gil->locked, 0, _Py_memory_order_release);
}

static void destroy_gil(struct _gil_runtime_state *gil)
static void destroy_gil(struct _gil_state *gil)
{
/* some pthread-like implementations tie the mutex to the cond
* and must have the cond destroyed first.
Expand All @@ -262,7 +262,7 @@ static void destroy_gil(struct _gil_runtime_state *gil)
}

#ifdef HAVE_FORK
static void recreate_gil(struct _gil_runtime_state *gil)
static void recreate_gil(struct _gil_state *gil)
{
_Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked);
/* XXX should we destroy the old OS resources here? */
Expand All @@ -274,7 +274,7 @@ static void
drop_gil(struct _ceval_runtime_state *ceval, struct _ceval_state *ceval2,
PyThreadState *tstate)
{
struct _gil_runtime_state *gil = &ceval->gil;
struct _gil_state *gil = &ceval->gil;
if (!_Py_atomic_load_relaxed(&gil->locked)) {
Py_FatalError("drop_gil: GIL is not locked");
}
Expand Down Expand Up @@ -358,7 +358,7 @@ take_gil(PyThreadState *tstate)
PyInterpreterState *interp = tstate->interp;
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
struct _ceval_state *ceval2 = &interp->ceval;
struct _gil_runtime_state *gil = &ceval->gil;
struct _gil_state *gil = &ceval->gil;

/* Check that _PyEval_InitThreads() was called to create the lock */
assert(gil_created(gil));
Expand Down Expand Up @@ -450,13 +450,13 @@ take_gil(PyThreadState *tstate)

void _PyEval_SetSwitchInterval(unsigned long microseconds)
{
struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
struct _gil_state *gil = &_PyRuntime.ceval.gil;
gil->interval = microseconds;
}

unsigned long _PyEval_GetSwitchInterval()
{
struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
struct _gil_state *gil = &_PyRuntime.ceval.gil;
return gil->interval;
}

Expand Down Expand Up @@ -484,7 +484,7 @@ _PyEval_InitGIL(PyThreadState *tstate)
return _PyStatus_OK();
}

struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
struct _gil_state *gil = &tstate->interp->runtime->ceval.gil;
assert(!gil_created(gil));

PyThread_init_thread();
Expand All @@ -506,7 +506,7 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
return;
}

struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
struct _gil_state *gil = &interp->runtime->ceval.gil;
if (!gil_created(gil)) {
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
yet: do nothing. */
Expand Down Expand Up @@ -598,7 +598,7 @@ _PyEval_ReInitThreads(PyThreadState *tstate)
{
_PyRuntimeState *runtime = tstate->interp->runtime;

struct _gil_runtime_state *gil = &runtime->ceval.gil;
struct _gil_state *gil = &runtime->ceval.gil;
if (!gil_created(gil)) {
return _PyStatus_OK();
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy