diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-11-02 16:37:08 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-11-02 16:47:50 -0300 |
commit | a1dd70b1d0e9ef155c81eeb249f137e763482d10 (patch) | |
tree | d80bf394168eb84f6eaf3630d091a40cf2b9e379 /src/nvim/os/signal.c | |
parent | e378965a4483881c3f737eed5c3d24cb1f305a62 (diff) | |
download | rneovim-a1dd70b1d0e9ef155c81eeb249f137e763482d10.tar.gz rneovim-a1dd70b1d0e9ef155c81eeb249f137e763482d10.tar.bz2 rneovim-a1dd70b1d0e9ef155c81eeb249f137e763482d10.zip |
event: Reintroduce the immediate event queue
Commit @264e0d872c("Remove automatic event deferral") removed the immediate
event queue because event deferral now had to be explicit. The problem is that
while some events don't need to be deferred, they still can result in recursive
`event_poll` calls, and recursion is not supported by libuv. Examples of those
are msgpack-rpc requests while a server->client request is pending, or signals
which can call `mch_exit`(and that will result in `uv_run` calls).
To fix the problem, this reintroduces the immediate event queue for events that
can potentially result in event loop recursion. The non-deferred events are
still processed in `event_poll`, but only after `uv_run` returns.
Diffstat (limited to 'src/nvim/os/signal.c')
-rw-r--r-- | src/nvim/os/signal.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 36f7b37c48..d913df4cbf 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -2,6 +2,8 @@ #include <uv.h> +#include "nvim/lib/klist.h" + #include "nvim/types.h" #include "nvim/ascii.h" #include "nvim/vim.h" @@ -13,6 +15,11 @@ #include "nvim/misc1.h" #include "nvim/misc2.h" #include "nvim/os/signal.h" +#include "nvim/os/event.h" + +#define SignalEventFreer(x) +KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer) +kmempool_t(SignalEventPool) *signal_event_pool = NULL; static uv_signal_t sint, spipe, shup, squit, sterm, swinch; #ifdef SIGPWR @@ -26,6 +33,7 @@ static bool rejecting_deadly; #endif void signal_init(void) { + signal_event_pool = kmp_init(SignalEventPool); uv_signal_init(uv_default_loop(), &sint); uv_signal_init(uv_default_loop(), &spipe); uv_signal_init(uv_default_loop(), &shup); @@ -113,6 +121,19 @@ static void deadly_signal(int signum) static void signal_cb(uv_signal_t *handle, int signum) { + int *n = kmp_alloc(SignalEventPool, signal_event_pool); + *n = signum; + event_push((Event) { + .handler = on_signal_event, + .data = n + }, false); +} + +static void on_signal_event(Event event) +{ + int signum = *((int *)event.data); + kmp_free(SignalEventPool, signal_event_pool, event.data); + switch (signum) { case SIGINT: got_int = true; @@ -142,3 +163,4 @@ static void signal_cb(uv_signal_t *handle, int signum) break; } } + |