diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-01 08:54:31 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-01 09:46:29 -0300 |
commit | 774f668c43c14c6c6593264a1c8c9a0275b19037 (patch) | |
tree | 176395e37139e68c3a40f9271b9cfa04722c0ff1 /src/os/input.c | |
parent | 40879af7bdd1633f3d22f0d1da9a24992cf3e2b2 (diff) | |
download | rneovim-774f668c43c14c6c6593264a1c8c9a0275b19037.tar.gz rneovim-774f668c43c14c6c6593264a1c8c9a0275b19037.tar.bz2 rneovim-774f668c43c14c6c6593264a1c8c9a0275b19037.zip |
Move signal handling to libuv event loop
This removes all signal handling code from os_unix.c to os/signal.c. Now signal
handling is done like this:
- Watchers for signals are registered with libuv default event loop
- `event_poll` continuously calls `poll_uv_loop` to produce events until it
receives user input, SIGINT or a timeout
- Any signals received in `poll_uv_loop` will push events to a queue that is
drained and processed by `event_poll`
Signals aren't handled directly in the libuv callback to avoid recursion in the
event loop(which isn't supported by libuv).
The same principle will apply to other events in the future: Push to a queue
from a libuv callback and drain it from `event_poll`
Diffstat (limited to 'src/os/input.c')
-rw-r--r-- | src/os/input.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/os/input.c b/src/os/input.c index 1e2d331fc0..14a7088024 100644 --- a/src/os/input.c +++ b/src/os/input.c @@ -1,3 +1,4 @@ +#include <string.h> #include <stdint.h> #include <stdbool.h> @@ -58,7 +59,7 @@ void input_init() } } -// Check if there's a pending input event +// Check if there's pending input bool input_ready() { return rbuffer.rpos < rbuffer.wpos || eof; @@ -126,11 +127,11 @@ int os_inchar(char_u *buf, int maxlen, int32_t ms, int tb_change_cnt) InbufPollResult result; if (ms >= 0) { - if ((result = inbuf_poll(ms)) != kInputAvail) { + if ((result = inbuf_poll(ms)) == kInputNone) { return 0; } } else { - if ((result = inbuf_poll(p_ut)) != kInputAvail) { + if ((result = inbuf_poll(p_ut)) == kInputNone) { if (trigger_cursorhold() && maxlen >= 3 && !typebuf_changed(tb_change_cnt)) { buf[0] = K_SPECIAL; @@ -177,9 +178,10 @@ static InbufPollResult inbuf_poll(int32_t ms) return kInputAvail; if (event_poll(ms)) { - if (rbuffer.rpos == rbuffer.wpos && eof) { + if (!got_int && rbuffer.rpos == rbuffer.wpos && eof) { return kInputEof; } + return kInputAvail; } |