diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-08-13 11:53:19 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-08-13 11:53:19 -0300 |
commit | f1de097dbb236ea400150f80b909407ca9af7441 (patch) | |
tree | 2d69f4f3a06f0ac5a4e936ec40bde81a26cf2b53 /src/nvim/event/process.c | |
parent | a816c726bbae4361a30c95b1226aaaa1dc76fd24 (diff) | |
download | rneovim-f1de097dbb236ea400150f80b909407ca9af7441.tar.gz rneovim-f1de097dbb236ea400150f80b909407ca9af7441.tar.bz2 rneovim-f1de097dbb236ea400150f80b909407ca9af7441.zip |
eval: Fix jobwait() to process multiple jobs concurrently
The new event processing architecture changed `jobwait()` semantics: Only one
job is processed at time since process_wait only focuses on one queue.
This fixes the problem with a few changes:
- Allow the event queue polled by `process_wait` to be overriden by a new
argument.
- Allow the parent queue to be overriden with `queue_replace_parent`
- Create a temporary queue that serves as the parent for all jobs passed to
`jobwait()`
Diffstat (limited to 'src/nvim/event/process.c')
-rw-r--r-- | src/nvim/event/process.c | 16 |
1 files changed, 10 insertions, 6 deletions
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--; |