◐ Shell
reader mode source ↗
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
2 changes: 1 addition & 1 deletion Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ struct _xidregitem {
PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(int64_t);

PyAPI_FUNC(int) _PyInterpreterState_IDInitref(struct _is *);
PyAPI_FUNC(void) _PyInterpreterState_IDIncref(struct _is *);
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(struct _is *);

#ifdef __cplusplus
Expand Down
12 changes: 9 additions & 3 deletions Objects/interpreteridobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ newinterpid(PyTypeObject *cls, int64_t id, int force)
}
}

interpid *self = PyObject_New(interpid, cls);
if (self == NULL) {
return NULL;
}
self->id = id;

if (interp != NULL) {
_PyInterpreterState_IDIncref(interp);
}
return self;
}

Expand Down
13 changes: 7 additions & 6 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,24 +493,25 @@ _PyInterpreterState_IDInitref(PyInterpreterState *interp)
}


void
_PyInterpreterState_IDIncref(PyInterpreterState *interp)
{
if (interp->id_mutex == NULL) {
return;
}
PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK);
interp->id_refcount += 1;
PyThread_release_lock(interp->id_mutex);
}


void
_PyInterpreterState_IDDecref(PyInterpreterState *interp)
{
if (interp->id_mutex == NULL) {
return;
}
struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK);
assert(interp->id_refcount != 0);
Expand Down
Toggle all file notes Toggle all file annotations