mirror of
https://github.com/python/cpython.git
synced 2025-07-12 22:05:16 +00:00
gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329)
This commit is contained in:
parent
518af37eb5
commit
f15795c9a0
19 changed files with 189 additions and 206 deletions
|
@ -65,11 +65,11 @@ contextvar_del(PyContextVar *var);
|
|||
|
||||
|
||||
#ifdef WITH_FREELISTS
|
||||
static struct _Py_context_state *
|
||||
get_context_state(void)
|
||||
static struct _Py_context_freelist *
|
||||
get_context_freelist(void)
|
||||
{
|
||||
_PyFreeListState *state = _PyFreeListState_GET();
|
||||
return &state->contexts;
|
||||
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||
return &freelists->contexts;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -341,11 +341,11 @@ _context_alloc(void)
|
|||
{
|
||||
PyContext *ctx;
|
||||
#ifdef WITH_FREELISTS
|
||||
struct _Py_context_state *state = get_context_state();
|
||||
if (state->numfree > 0) {
|
||||
state->numfree--;
|
||||
ctx = state->freelist;
|
||||
state->freelist = (PyContext *)ctx->ctx_weakreflist;
|
||||
struct _Py_context_freelist *context_freelist = get_context_freelist();
|
||||
if (context_freelist->numfree > 0) {
|
||||
context_freelist->numfree--;
|
||||
ctx = context_freelist->freelist;
|
||||
context_freelist->freelist = (PyContext *)ctx->ctx_weakreflist;
|
||||
OBJECT_STAT_INC(from_freelist);
|
||||
ctx->ctx_weakreflist = NULL;
|
||||
_Py_NewReference((PyObject *)ctx);
|
||||
|
@ -468,11 +468,11 @@ context_tp_dealloc(PyContext *self)
|
|||
(void)context_tp_clear(self);
|
||||
|
||||
#ifdef WITH_FREELISTS
|
||||
struct _Py_context_state *state = get_context_state();
|
||||
if (state->numfree >= 0 && state->numfree < PyContext_MAXFREELIST) {
|
||||
state->numfree++;
|
||||
self->ctx_weakreflist = (PyObject *)state->freelist;
|
||||
state->freelist = self;
|
||||
struct _Py_context_freelist *context_freelist = get_context_freelist();
|
||||
if (context_freelist->numfree >= 0 && context_freelist->numfree < PyContext_MAXFREELIST) {
|
||||
context_freelist->numfree++;
|
||||
self->ctx_weakreflist = (PyObject *)context_freelist->freelist;
|
||||
context_freelist->freelist = self;
|
||||
OBJECT_STAT_INC(to_freelist);
|
||||
}
|
||||
else
|
||||
|
@ -1267,10 +1267,10 @@ get_token_missing(void)
|
|||
|
||||
|
||||
void
|
||||
_PyContext_ClearFreeList(_PyFreeListState *freelist_state, int is_finalization)
|
||||
_PyContext_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization)
|
||||
{
|
||||
#ifdef WITH_FREELISTS
|
||||
struct _Py_context_state *state = &freelist_state->contexts;
|
||||
struct _Py_context_freelist *state = &freelists->contexts;
|
||||
for (; state->numfree > 0; state->numfree--) {
|
||||
PyContext *ctx = state->freelist;
|
||||
state->freelist = (PyContext *)ctx->ctx_weakreflist;
|
||||
|
|
|
@ -1721,7 +1721,7 @@ _PyGC_ClearAllFreeLists(PyInterpreterState *interp)
|
|||
HEAD_LOCK(&_PyRuntime);
|
||||
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)interp->threads.head;
|
||||
while (tstate != NULL) {
|
||||
_PyObject_ClearFreeLists(&tstate->freelist_state, 0);
|
||||
_PyObject_ClearFreeLists(&tstate->freelists, 0);
|
||||
tstate = (_PyThreadStateImpl *)tstate->base.next;
|
||||
}
|
||||
HEAD_UNLOCK(&_PyRuntime);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
void
|
||||
_PyGC_ClearAllFreeLists(PyInterpreterState *interp)
|
||||
{
|
||||
_PyObject_ClearFreeLists(&interp->freelist_state, 0);
|
||||
_PyObject_ClearFreeLists(&interp->object_state.freelists, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,22 +8,22 @@
|
|||
extern _PyObjectStackChunk *_PyObjectStackChunk_New(void);
|
||||
extern void _PyObjectStackChunk_Free(_PyObjectStackChunk *);
|
||||
|
||||
static struct _Py_object_stack_state *
|
||||
get_state(void)
|
||||
static struct _Py_object_stack_freelist *
|
||||
get_object_stack_freelist(void)
|
||||
{
|
||||
_PyFreeListState *state = _PyFreeListState_GET();
|
||||
return &state->object_stacks;
|
||||
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||
return &freelists->object_stacks;
|
||||
}
|
||||
|
||||
_PyObjectStackChunk *
|
||||
_PyObjectStackChunk_New(void)
|
||||
{
|
||||
_PyObjectStackChunk *buf;
|
||||
struct _Py_object_stack_state *state = get_state();
|
||||
if (state->numfree > 0) {
|
||||
buf = state->free_list;
|
||||
state->free_list = buf->prev;
|
||||
state->numfree--;
|
||||
struct _Py_object_stack_freelist *obj_stack_freelist = get_object_stack_freelist();
|
||||
if (obj_stack_freelist->numfree > 0) {
|
||||
buf = obj_stack_freelist->free_list;
|
||||
obj_stack_freelist->free_list = buf->prev;
|
||||
obj_stack_freelist->numfree--;
|
||||
}
|
||||
else {
|
||||
// NOTE: we use PyMem_RawMalloc() here because this is used by the GC
|
||||
|
@ -43,13 +43,13 @@ void
|
|||
_PyObjectStackChunk_Free(_PyObjectStackChunk *buf)
|
||||
{
|
||||
assert(buf->n == 0);
|
||||
struct _Py_object_stack_state *state = get_state();
|
||||
if (state->numfree >= 0 &&
|
||||
state->numfree < _PyObjectStackChunk_MAXFREELIST)
|
||||
struct _Py_object_stack_freelist *obj_stack_freelist = get_object_stack_freelist();
|
||||
if (obj_stack_freelist->numfree >= 0 &&
|
||||
obj_stack_freelist->numfree < _PyObjectStackChunk_MAXFREELIST)
|
||||
{
|
||||
buf->prev = state->free_list;
|
||||
state->free_list = buf;
|
||||
state->numfree++;
|
||||
buf->prev = obj_stack_freelist->free_list;
|
||||
obj_stack_freelist->free_list = buf;
|
||||
obj_stack_freelist->numfree++;
|
||||
}
|
||||
else {
|
||||
PyMem_RawFree(buf);
|
||||
|
@ -89,7 +89,7 @@ _PyObjectStack_Merge(_PyObjectStack *dst, _PyObjectStack *src)
|
|||
}
|
||||
|
||||
void
|
||||
_PyObjectStackChunk_ClearFreeList(_PyFreeListState *free_lists, int is_finalization)
|
||||
_PyObjectStackChunk_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization)
|
||||
{
|
||||
if (!is_finalization) {
|
||||
// Ignore requests to clear the free list during GC. We use object
|
||||
|
@ -97,7 +97,7 @@ _PyObjectStackChunk_ClearFreeList(_PyFreeListState *free_lists, int is_finalizat
|
|||
return;
|
||||
}
|
||||
|
||||
struct _Py_object_stack_state *state = &free_lists->object_stacks;
|
||||
struct _Py_object_stack_freelist *state = &freelists->object_stacks;
|
||||
while (state->numfree > 0) {
|
||||
_PyObjectStackChunk *buf = state->free_list;
|
||||
state->free_list = buf->prev;
|
||||
|
|
|
@ -1795,8 +1795,8 @@ finalize_interp_types(PyInterpreterState *interp)
|
|||
#ifndef Py_GIL_DISABLED
|
||||
// With Py_GIL_DISABLED:
|
||||
// the freelists for the current thread state have already been cleared.
|
||||
_PyFreeListState *state = _PyFreeListState_GET();
|
||||
_PyObject_ClearFreeLists(state, 1);
|
||||
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||
_PyObject_ClearFreeLists(freelists, 1);
|
||||
#endif
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
|
|
|
@ -1548,8 +1548,8 @@ PyThreadState_Clear(PyThreadState *tstate)
|
|||
}
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// Each thread should clear own freelists in free-threading builds.
|
||||
_PyFreeListState *freelist_state = _PyFreeListState_GET();
|
||||
_PyObject_ClearFreeLists(freelist_state, 1);
|
||||
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||
_PyObject_ClearFreeLists(freelists, 1);
|
||||
|
||||
// Remove ourself from the biased reference counting table of threads.
|
||||
_Py_brc_remove_thread(tstate);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue