8000 gh-76785: Clean Up the Channels Module by ericsnowcurrently · Pull Request #110568 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-76785: Clean Up the Channels Module #110568

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

Merged
Merged
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
_PyChannelState -> _channel_state
  • Loading branch information
ericsnowcurrently committed Oct 17, 2023
commit b85ea2692c9d1dd49f011685a95170aa1f46ac67
58 changes: 29 additions & 29 deletions Modules/_xxinterpchannelsmodule.c
EDBE
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,12 @@ typedef struct _channel {
_channelends *ends;
int open;
struct _channel_closing *closing;
} _PyChannelState;
} _channel_state;

static _PyChannelState *
static _channel_state *
_channel_new(PyThread_type_lock mutex)
{
_PyChannelState *chan = GLOBAL_MALLOC(_PyChannelState);
_channel_state *chan = GLOBAL_MALLOC(_channel_state);
if (chan == NULL) {
return NULL;
}
Expand All @@ -1215,7 +1215,7 @@ _channel_new(PyThread_type_lock mutex)
}

static void
_channel_free(_PyChannelState *chan)
_channel_free(_channel_state *chan)
{
_channel_clear_closing(chan);
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);
Expand All @@ -1228,7 +1228,7 @@ _channel_free(_PyChannelState *chan)
}

static int
_channel_add(_PyChannelState *chan, int64_t interpid,
_channel_add(_channel_state *chan, int64_t interpid,
_PyCrossInterpreterData *data, _waiting_t *waiting)
{
int res = -1;
Expand All @@ -1255,7 +1255,7 @@ _channel_add(_PyChannelState *chan, int64_t interpid,
}

static int
_channel_next(_PyChannelState *chan, int64_t interpid,
_channel_next(_channel_state *chan, int64_t interpid,
_PyCrossInterpreterData **p_data, _waiting_t **p_waiting)
{
int err = 0;
Expand Down Expand Up @@ -1286,7 +1286,7 @@ _channel_next(_PyChannelState *chan, int64_t interpid,
}

static void
_channel_remove(_PyChannelState *chan, _channelitem_id_t itemid)
_channel_remove(_channel_state *chan, _channelitem_id_t itemid)
{
_PyCrossInterpreterData *data = NULL;
_waiting_t *waiting = NULL;
Expand All @@ -1306,7 +1306,7 @@ _channel_remove(_PyChannelState *chan, _channelitem_id_t itemid)
}

static int
_channel_release_interpreter(_PyChannelState *chan, int64_t interpid, int end)
_channel_release_interpreter(_channel_state *chan, int64_t interpid, int end)
{
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);

Expand All @@ -1330,7 +1330,7 @@ _channel_release_interpreter(_PyChannelState *chan, int64_t interpid, int end)
}

static int
_channel_release_all(_PyChannelState *chan, int end, int force)
_channel_release_all(_channel_state *chan, int end, int force)
{
int res = -1;
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);
Expand Down Expand Up @@ -1359,7 +1359,7 @@ _channel_release_all(_PyChannelState *chan, int end, int force)
}

static void
_channel_clear_interpreter(_PyChannelState *chan, int64_t interpid)
_channel_clear_interpreter(_channel_state *chan, int64_t interpid)
{
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);

Expand All @@ -1377,14 +1377,14 @@ struct _channelref;

typedef struct _channelref {
int64_t cid;
_PyChannelState *chan;
_channel_state *chan;
struct _channelref *next;
// The number of ChannelID objects referring to this channel.
Py_ssize_t objcount;
} _channelref;

static _channelref *
_channelref_new(int64_t cid, _PyChannelState *chan)
_channelref_new(int64_t cid, _channel_state *chan)
{
_channelref *ref = GLOBAL_MALLOC(_channelref);
if (ref == NULL) {
Expand Down Expand Up @@ -1476,10 +1476,10 @@ _channels_next_id(_channels *channels) // needs lock

static int
_channels_lookup(_channels *channels, int64_t cid, PyThread_type_lock *pmutex,
_PyChannelState **res)
_channel_state **res)
{
int err = -1;
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
if (pmutex != NULL) {
*pmutex = NULL;
Expand Down Expand Up @@ -1512,7 +1512,7 @@ _channels_lookup(_channels *channels, int64_t cid, PyThread_type_lock *pmutex,
}

static int64_t
_channels_add(_channels *channels, _PyChannelState *chan)
_channels_add(_channels *channels, _channel_state *chan)
{
int64_t cid = -1;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
Expand Down Expand Up @@ -1544,7 +1544,7 @@ _channels_add(_channels *channels, _PyChannelState *chan)
static int _channel_set_closing(_channelref *, PyThread_type_lock);

static int
_channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
_channels_close(_channels *channels, int64_t cid, _channel_state **pchan,
int end, int force)
{
int res = -1;
Expand Down Expand Up @@ -1610,7 +1610,7 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,

static void
_channels_remove_ref(_channels *channels, _channelref *ref, _channelref *prev,
_PyChannelState **pchan)
_channel_state **pchan)
{
if (ref == channels->head) {
channels->head = ref->next;
Expand All @@ -1627,7 +1627,7 @@ _channels_remove_ref(_channels *channels, _channelref *ref, _channelref *prev,
}

static int
_channels_remove(_channels *channels, int64_t cid, _PyChannelState **pchan)
_channels_remove(_channels *channels, int64_t cid, _channel_state **pchan)
{
int res = -1;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
Expand Down Expand Up @@ -1685,7 +1685,7 @@ _channels_release_cid_object(_channels *channels, int64_t cid)

// Destroy if no longer used.
if (ref->objcount == 0) {
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
_channels_remove_ref(channels, ref, prev, &chan);
if (chan != NULL) {
_channel_free(chan);
Expand Down Expand Up @@ -1741,7 +1741,7 @@ struct _channel_closing {

static int
_channel_set_closing(_channelref *ref, PyThread_type_lock mutex) {
_PyChannelState *chan = ref->chan;
_channel_state *chan = ref->chan;
if (chan == NULL) {
// already closed
return 0;
Expand All @@ -1765,7 +1765,7 @@ _channel_set_closing(_channelref *ref, PyThread_type_lock mutex) {
}

static void
_channel_clear_closing(_PyChannelState *chan) {
_channel_clear_closing(_channel_state *chan) {
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);
if (chan->closing != NULL) {
GLOBAL_FREE(chan->closing);
Expand All @@ -1775,7 +1775,7 @@ _channel_clear_closing(_PyChannelState *chan) {
}

static void
_channel_finish_closing(_PyChannelState *chan) {
_channel_finish_closing(_channel_state *chan) {
struct _channel_closing *closing = chan->closing;
if (closing == NULL) {
return;
Expand All @@ -1798,7 +1798,7 @@ channel_create(_channels *channels)
if (mutex == NULL) {
return ERR_CHANNEL_MUTEX_INIT;
}
_PyChannelState *chan = _channel_new(mutex);
_channel_state *chan = _channel_new(mutex);
if (chan == NULL) {
PyThread_free_lock(mutex);
return -1;
Expand All @@ -1814,7 +1814,7 @@ channel_create(_channels *channels)
static int
channel_destroy(_channels *channels, int64_t cid)
{
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
int err = _channels_remove(channels, cid, &chan);
if (err != 0) {
return err;
Expand All @@ -1840,7 +1840,7 @@ channel_send(_channels *channels, int64_t cid, PyObject *obj,

// Look up the channel.
PyThread_type_lock mutex = NULL;
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
int err = _channels_lookup(channels, cid, &mutex, &chan);
if (err != 0) {
return err;
Expand Down Expand Up @@ -1884,7 +1884,7 @@ channel_clear_sent(_channels *channels, int64_t cid, _waiting_t *waiting)
{
// Look up the channel.
PyThread_type_lock mutex = NULL;
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
int err = _channels_lookup(channels, cid, &mutex, &chan);
if (err != 0) {
// The channel was already closed, etc.
Expand Down Expand Up @@ -1973,7 +1973,7 @@ channel_recv(_channels *channels, int64_t cid, PyObject **res)

// Look up the channel.
PyThread_type_lock mutex = NULL;
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
err = _channels_lookup(channels, cid, &mutex, &chan);
if (err != 0) {
return err;
Expand Down Expand Up @@ -2040,7 +2040,7 @@ channel_release(_channels *channels, int64_t cid, int send, int recv)

// Look up the channel.
PyThread_type_lock mutex = NULL;
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
int err = _channels_lookup(channels, cid, &mutex, &chan);
if (err != 0) {
return err;
Expand Down Expand Up @@ -2068,7 +2068,7 @@ static int
channel_is_associated(_channels *channels, int64_t cid, int64_t interpid,
int send)
{
_PyChannelState *chan = NULL;
_channel_state *chan = NULL;
int err = _channels_lookup(channels, cid, NULL, &chan);
if (err != 0) {
return err;
Expand Down
0