Skip to content
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

Add Float shareable #36

Open
wants to merge 21 commits into
base: per-interpreter-gil
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2aad06a
Add a comment.
ericsnowcurrently Sep 12, 2022
e55fbdd
_gil_runtime_state -> _gil_state.
ericsnowcurrently Sep 12, 2022
711b19d
Pass PyInterpreterState to _PyEval_ThreadInitialized().
ericsnowcurrently Sep 12, 2022
dba4460
runtime->main -> runtime->interpreters.main.
ericsnowcurrently Sep 12, 2022
5342672
Pass PyInterpreterState to _PyEval_InitState().
ericsnowcurrently Sep 12, 2022
f2361d7
Label some struct fields.
ericsnowcurrently Sep 12, 2022
adc09a0
Add _get_gil().
ericsnowcurrently Sep 12, 2022
7014bff
Pass the runtime to _PyEval_InitRuntimeState().
ericsnowcurrently Sep 12, 2022
2026034
Add some comments.
ericsnowcurrently Sep 12, 2022
3ce9695
Add _GET_OWN_GIL().
ericsnowcurrently Sep 12, 2022
57ca2fa
Pass PyInterpreterState to _PyEval_FiniState().
ericsnowcurrently Sep 12, 2022
936c86d
Call _gil_initialize() in _PyEval_InitState().
ericsnowcurrently Sep 12, 2022
66ca3e4
Drop _PyEval_InitRuntimeState().
ericsnowcurrently Sep 12, 2022
6d09320
Move the GIL to PyInterpreterState (but still share).
ericsnowcurrently Sep 12, 2022
5075992
Keep sharing the GIL.
ericsnowcurrently Sep 12, 2022
f39c883
Check for GIL ownership.
ericsnowcurrently Sep 12, 2022
ae2eb3c
Stop sharing the GIL if configured as "isolated".
ericsnowcurrently Sep 12, 2022
b984a34
add bool as shareable
tonybaloney May 3, 2023
ea4c9ea
add shareable floats
tonybaloney May 3, 2023
f60d87c
use ll literal to avoid the upcast warning in MSVC
tonybaloney May 3, 2023
4db7753
Merge branch 'per-interpreter-gil' into float_shareable
tonybaloney May 3, 2023
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
7 changes: 3 additions & 4 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ struct _ceval_runtime_state;


extern void _Py_FinishPendingCalls(PyThreadState *tstate);
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
extern void _PyEval_FiniState(struct _ceval_state *ceval);
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
extern void _PyEval_FiniState(PyInterpreterState *);
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyEval_AddPendingCall(
PyInterpreterState *interp,
Expand Down Expand Up @@ -103,7 +102,7 @@ _PyEval_Vector(PyThreadState *tstate,
PyObject* const* args, size_t argcount,
PyObject *kwnames);

extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
extern void _PyEval_FiniGIL(PyInterpreterState *interp);

Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ extern "C" {
#undef FORCE_SWITCHING
#define FORCE_SWITCHING

struct _gil_runtime_state {
/* ** The GIL ** */
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
4 changes: 4 additions & 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 Expand Up @@ -49,6 +50,9 @@ struct _ceval_state {
_Py_atomic_int eval_breaker;
/* Request for dropping the GIL */
_Py_atomic_int gil_drop_request;
/* The GIL */
struct _gil_state gil;
/* Pending calls */
struct _pending_calls pending;
};

Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern "C" {
#endif

#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_gil.h" // struct _gil_runtime_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 +25,6 @@ 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;
};

/* GIL state */
Expand Down
12 changes: 9 additions & 3 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def test_default_shareables(self):
'spam',
10,
-10,
True,
False,
100.0,
]
for obj in shareables:
with self.subTest(obj):
Expand All @@ -331,16 +334,13 @@ class SubBytes(bytes):

not_shareables = [
# singletons
True,
False,
NotImplemented,
...,
# builtin types and objects
type,
object,
object(),
Exception(),
100.0,
# user-defined types and objects
Cheese,
Cheese('Wensleydale'),
Expand Down Expand Up @@ -400,6 +400,12 @@ def test_int(self):
self._assert_values(itertools.chain(range(-1, 258),
[sys.maxsize, -sys.maxsize - 1]))

def test_float(self):
self._assert_values([0.0, 1.1, -1.0, 0.12345678, -0.12345678])

def test_bool(self):
self._assert_values(True, False)

def test_non_shareable_int(self):
ints = [
sys.maxsize + 1,
Expand Down
Loading