8000 Refactor no-gil structs and update test · python/cpython@80fbe3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 80fbe3b

Browse files
committed
Refactor no-gil structs and update test
1 parent 2be6ed5 commit 80fbe3b

File tree

5 files changed

+65
-55
lines changed

5 files changed

+65
-55
lines changed

Include/internal/pycore_index_pool.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,12 @@ extern "C" {
1313

1414
#ifdef Py_GIL_DISABLED
1515

16+
#include "pycore_interp_structs.h"
17+
1618
// This contains code for allocating unique indices in an array. It is used by
1719
// the free-threaded build to assign each thread a globally unique index into
1820
// each code object's thread-local bytecode array.
1921

20-
// A min-heap of indices
21-
typedef struct _PyIndexHeap {
22-
int32_t *values;
23-
24-
// Number of items stored in values
25-
Py_ssize_t size;
26-
27-
// Maximum number of items that can be stored in values
28-
Py_ssize_t capacity;
29-
} _PyIndexHeap;
30-
31-
// An unbounded pool of indices. Indices are allocated starting from 0. They
32-
// may be released back to the pool once they are no longer in use.
33-
typedef struct _PyIndexPool {
34-
PyMutex mutex;
35-
36-
// Min heap of indices available for allocation
37-
_PyIndexHeap free_indices;
38-
39-
// Next index to allocate if no free indices are available
40-
int32_t next_index;
41-
} _PyIndexPool;
4222

4323
// Allocate the smallest available index. Returns -1 on error.
4424
extern int32_t _PyIndexPool_AllocIndex(_PyIndexPool *indices);

Include/internal/pycore_interp.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ extern "C" {
4343

4444

4545

46-
#ifdef Py_GIL_DISABLED
47-
// This should be prime but otherwise the choice is arbitrary. A larger value
48-
// increases concurrency at the expense of memory.
49-
# define NUM_WEAKREF_LIST_LOCKS 127
50-
#endif
51-
5246
/* interpreter state */
5347

5448
#define _PyInterpreterState_WHENCE_NOTSET -1

Include/internal/pycore_interp_structs.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ extern "C" {
1919
#define TYPE_MAX_WATCHERS 8
2020

2121

22+
#ifdef Py_GIL_DISABLED
23+
// This should be prime but otherwise the choice is arbitrary. A larger value
24+
// increases concurrency at the expense of memory.
25+
# define NUM_WEAKREF_LIST_LOCKS 127
26+
#endif
27+
2228
typedef int (*_Py_pending_call_func)(void *);
2329

2430
struct _pending_call {
@@ -697,6 +703,56 @@ struct _Py_interp_static_objects {
697703

698704
#include "pycore_instruments.h"
699705

706+
707+
#ifdef Py_GIL_DISABLED
708+
709+
// A min-heap of indices
710+
typedef struct _PyIndexHeap {
711+
int32_t *values;
712+
713+
// Number of items stored in values
714+
Py_ssize_t size;
715+
716+
// Maximum number of items that can be stored in values
717+
Py_ssize_t capacity;
718+
} _PyIndexHeap;
719+
720+
// An unbounded pool of indices. Indices are allocated starting from 0. They
721+
// may be released back to the pool once they are no longer in use.
722+
typedef struct _PyIndexPool {
723+
PyMutex mutex;
724+
725+
// Min heap of indices available for allocation
726+
_PyIndexHeap free_indices;
727+
728+
// Next index to allocate if no free indices are available
729+
int32_t next_index;
730+
} _PyIndexPool;
731+
732+
typedef union _Py_unique_id_entry {
733+
// Points to the next free type id, when part of the freelist
734+
union _Py_unique_id_entry *next;
735+
736+
// Stores the object when the id is assigned
737+
PyObject *obj;
738+
} _Py_unique_id_entry;
739+
740+
struct _Py_unique_id_pool {
741+
PyMutex mutex;
742+
743+
// combined table of object with allocated unique ids and unallocated ids.
744+
_Py_unique_id_entry *table;
745+
746+
// Next entry to allocate inside 'table' or NULL
747+
_Py_unique_id_entry *freelist;
748+
749+
// size of 'table'
750+
Py_ssize_t size;
751+
};
752+
753+
#endif
754+
755+
700756
/* PyInterpreterState holds the global state for one of the runtime's
701757
interpreters. Typically the initial (main) interpreter is the only one.
702758

Include/internal/pycore_uniqueid.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@ extern "C" {
2424
// Each entry implicitly represents a unique id based on its offset in the
2525
// table. Non-allocated entries form a free-list via the 'next' pointer.
2626
// Allocated entries store the corresponding PyObject.
27-
typedef union _Py_unique_id_entry {
28-
// Points to the next free type id, when part of the freelist
29-
union _Py_unique_id_entry *next;
30-
31-
// Stores the object when the id is assigned
32-
PyObject *obj;
33-
} _Py_unique_id_entry;
34-
35-
struct _Py_unique_id_pool {
36-
PyMutex mutex;
37-
38-
// combined table of object with allocated unique ids and unallocated ids.
39-
_Py_unique_id_entry *table;
40-
41-
// Next entry to allocate inside 'table' or NULL
42-
_Py_unique_id_entry *freelist;
43-
44-
// size of 'table'
45-
Py_ssize_t size;
46-
};
4727

4828
#define _Py_INVALID_UNIQUE_ID 0
4929

Programs/test_frozenmain.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0