refactor(multiqueue): rename multiqueue_new_parent #32767

This commit is contained in:
Justin M. Keyes
2025-03-08 12:28:15 -08:00
committed by GitHub
parent d5ff0aff27
commit 05b9daa1e6
6 changed files with 16 additions and 14 deletions

View File

@ -4191,7 +4191,7 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
list_T *args = argvars[0].vval.v_list;
Channel **jobs = xcalloc((size_t)tv_list_len(args), sizeof(*jobs));
MultiQueue *waiting_jobs = multiqueue_new_parent(loop_on_put, &main_loop);
MultiQueue *waiting_jobs = multiqueue_new(loop_on_put, &main_loop);
// Validate, prepare jobs for waiting.
int i = 0;

View File

@ -21,9 +21,9 @@ void loop_init(Loop *loop, void *data)
loop->closing = false;
loop->uv.data = loop;
kv_init(loop->children);
loop->events = multiqueue_new_parent(loop_on_put, loop);
loop->events = multiqueue_new(loop_on_put, loop);
loop->fast_events = multiqueue_new_child(loop->events);
loop->thread_events = multiqueue_new_parent(NULL, NULL);
loop->thread_events = multiqueue_new(NULL, NULL);
uv_mutex_init(&loop->mutex);
uv_async_init(&loop->uv, &loop->async, async_cb);
uv_signal_init(&loop->uv, &loop->children_watcher);

View File

@ -67,7 +67,7 @@ struct multiqueue_item {
struct multiqueue {
MultiQueue *parent;
QUEUE headtail; // circularly-linked
PutCallback put_cb;
PutCallback on_put; // Called on the parent (if any) when an item is enqueued in a child.
void *data;
size_t size;
};
@ -84,26 +84,28 @@ typedef struct {
static Event NILEVENT = { .handler = NULL, .argv = { NULL } };
MultiQueue *multiqueue_new_parent(PutCallback put_cb, void *data)
/// Creates a new root (parentless) queue, which may gain child queues via `multiqueue_new_child`.
MultiQueue *multiqueue_new(PutCallback on_put, void *data)
{
return multiqueue_new(NULL, put_cb, data);
return _multiqueue_new(NULL, on_put, data);
}
/// Creates a new queue as a child of a `parent` queue.
MultiQueue *multiqueue_new_child(MultiQueue *parent)
FUNC_ATTR_NONNULL_ALL
{
assert(!parent->parent); // parent cannot have a parent, more like a "root"
parent->size++;
return multiqueue_new(parent, NULL, NULL);
return _multiqueue_new(parent, NULL, NULL);
}
static MultiQueue *multiqueue_new(MultiQueue *parent, PutCallback put_cb, void *data)
static MultiQueue *_multiqueue_new(MultiQueue *parent, PutCallback on_put, void *data)
{
MultiQueue *rv = xmalloc(sizeof(MultiQueue));
QUEUE_INIT(&rv->headtail);
rv->size = 0;
rv->parent = parent;
rv->put_cb = put_cb;
rv->on_put = on_put;
rv->data = data;
return rv;
}
@ -135,8 +137,8 @@ void multiqueue_put_event(MultiQueue *self, Event event)
{
assert(self);
multiqueue_push(self, event);
if (self->parent && self->parent->put_cb) {
self->parent->put_cb(self->parent, self->parent->data);
if (self->parent && self->parent->on_put) {
self->parent->on_put(self->parent, self->parent->data);
}
}

View File

@ -498,7 +498,7 @@ void terminal_open(Terminal **termpp, buf_T *buf, TerminalOptions opts)
// can create an infinite loop (#32753).
// This queue is never processed directly: when the terminal is refreshed, all
// events from this queue are copied back onto the main event queue.
term->pending.events = multiqueue_new_parent(NULL, NULL);
term->pending.events = multiqueue_new(NULL, NULL);
aco_save_T aco;
aucmd_prepbuf(&aco, buf);

View File

@ -1,4 +1,4 @@
// Terminal UI functions. Invoked (by ui_client.c) on the UI process.
// Terminal UI functions. Invoked by the UI process (ui_client.c), not the server.
#include <assert.h>
#include <inttypes.h>

View File

@ -25,7 +25,7 @@ describe('multiqueue (multi-level event-queue)', function()
before_each(function()
child_call_once(function()
parent = multiqueue.multiqueue_new_parent(ffi.NULL, ffi.NULL)
parent = multiqueue.multiqueue_new(ffi.NULL, ffi.NULL)
child1 = multiqueue.multiqueue_new_child(parent)
child2 = multiqueue.multiqueue_new_child(parent)
child3 = multiqueue.multiqueue_new_child(parent)