diff options
Diffstat (limited to 'src/nvim/event')
-rw-r--r-- | src/nvim/event/loop.c | 4 | ||||
-rw-r--r-- | src/nvim/event/process.c | 16 | ||||
-rw-r--r-- | src/nvim/event/queue.c | 6 |
3 files changed, 18 insertions, 8 deletions
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c index 1a50ec0d9a..3d3288f858 100644 --- a/src/nvim/event/loop.c +++ b/src/nvim/event/loop.c @@ -22,7 +22,7 @@ void loop_init(Loop *loop, void *data) loop->uv.data = loop; loop->children = kl_init(WatcherPtr); loop->children_stop_requests = 0; - loop->events = queue_new_parent(on_put, loop); + loop->events = queue_new_parent(loop_on_put, loop); loop->fast_events = queue_new_child(loop->events); uv_signal_init(&loop->uv, &loop->children_watcher); uv_timer_init(&loop->uv, &loop->children_kill_timer); @@ -59,7 +59,7 @@ void loop_poll_events(Loop *loop, int ms) queue_process_events(loop->fast_events); } -static void on_put(Queue *queue, void *data) +void loop_on_put(Queue *queue, void *data) { Loop *loop = data; // Sometimes libuv will run pending callbacks(timer for example) before diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 54dbc11a03..81d4e690c3 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -152,7 +152,7 @@ void process_close_err(Process *proc) FUNC_ATTR_NONNULL_ALL /// indistinguishable from the process returning -1 by itself. Which /// is possible on some OS. Returns -2 if an user has interruped the /// wait. -int process_wait(Process *proc, int ms) FUNC_ATTR_NONNULL_ALL +int process_wait(Process *proc, int ms, Queue *events) FUNC_ATTR_NONNULL_ARG(1) { // The default status is -1, which represents a timeout int status = -1; @@ -162,10 +162,14 @@ int process_wait(Process *proc, int ms) FUNC_ATTR_NONNULL_ALL return proc->status; } + if (!events) { + events = proc->events; + } + // Increase refcount to stop the exit callback from being called(and possibly // being freed) before we have a chance to get the status. proc->refcount++; - LOOP_PROCESS_EVENTS_UNTIL(proc->loop, proc->events, ms, + LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, ms, // Until... got_int || // interrupted by the user proc->refcount == 1); // job exited @@ -179,10 +183,10 @@ int process_wait(Process *proc, int ms) FUNC_ATTR_NONNULL_ALL if (ms == -1) { // We can only return if all streams/handles are closed and the job // exited. - LOOP_PROCESS_EVENTS_UNTIL(proc->loop, proc->events, -1, + LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, -1, proc->refcount == 1); } else { - LOOP_PROCESS_EVENTS(proc->loop, proc->events, 0); + LOOP_PROCESS_EVENTS(proc->loop, events, 0); } } @@ -191,9 +195,9 @@ int process_wait(Process *proc, int ms) FUNC_ATTR_NONNULL_ALL // resources status = interrupted ? -2 : proc->status; decref(proc); - if (proc->events) { + if (events) { // the decref call created an exit event, process it now - queue_process_events(proc->events); + queue_process_events(events); } } else { proc->refcount--; diff --git a/src/nvim/event/queue.c b/src/nvim/event/queue.c index 3f03dd444e..19eca14144 100644 --- a/src/nvim/event/queue.c +++ b/src/nvim/event/queue.c @@ -152,6 +152,12 @@ bool queue_empty(Queue *queue) return QUEUE_EMPTY(&queue->headtail); } +void queue_replace_parent(Queue *queue, Queue *new_parent) +{ + assert(queue_empty(queue)); + queue->parent = new_parent; +} + static Event queue_remove(Queue *queue) { assert(!queue_empty(queue)); |