diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-07-16 23:10:04 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-07-17 00:19:19 -0300 |
commit | 991d3ec1e679bb6407f2a5820910d2968424183c (patch) | |
tree | 38810fb657e1e1ea9d77b7a7963e874e8bda99d1 /src/nvim/os | |
parent | 9e42ef4e1312fb6888d2691e9d979b95dd43ec94 (diff) | |
download | rneovim-991d3ec1e679bb6407f2a5820910d2968424183c.tar.gz rneovim-991d3ec1e679bb6407f2a5820910d2968424183c.tar.bz2 rneovim-991d3ec1e679bb6407f2a5820910d2968424183c.zip |
event loop: New abstraction layer with refactored time/signal API
- Add event loop abstraction module under src/nvim/event. The
src/nvim/event/loop module replaces src/nvim/os/event
- Remove direct dependency on libuv signal/timer API and use the new abstraction
instead.
- Replace all references to uv_default_loop() by &loop.uv, a new global variable
that wraps libuv main event loop but allows the event loop functions to be
reused in other contexts.
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/event.c | 177 | ||||
-rw-r--r-- | src/nvim/os/event.h | 35 | ||||
-rw-r--r-- | src/nvim/os/event_defs.h | 17 | ||||
-rw-r--r-- | src/nvim/os/input.c | 10 | ||||
-rw-r--r-- | src/nvim/os/job.c | 40 | ||||
-rw-r--r-- | src/nvim/os/job.h | 2 | ||||
-rw-r--r-- | src/nvim/os/job_private.h | 5 | ||||
-rw-r--r-- | src/nvim/os/pipe_process.c | 10 | ||||
-rw-r--r-- | src/nvim/os/pty_process.c | 8 | ||||
-rw-r--r-- | src/nvim/os/rstream.c | 6 | ||||
-rw-r--r-- | src/nvim/os/rstream.h | 1 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 2 | ||||
-rw-r--r-- | src/nvim/os/signal.c | 51 | ||||
-rw-r--r-- | src/nvim/os/signal.h | 2 | ||||
-rw-r--r-- | src/nvim/os/time.c | 4 | ||||
-rw-r--r-- | src/nvim/os/wstream.c | 2 |
16 files changed, 74 insertions, 298 deletions
diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c deleted file mode 100644 index 56874b495d..0000000000 --- a/src/nvim/os/event.c +++ /dev/null @@ -1,177 +0,0 @@ -#include <assert.h> -#include <stdint.h> -#include <stdbool.h> -#include <stdlib.h> - -#include <uv.h> - -#include "nvim/os/event.h" -#include "nvim/os/input.h" -#include "nvim/msgpack_rpc/defs.h" -#include "nvim/msgpack_rpc/channel.h" -#include "nvim/msgpack_rpc/server.h" -#include "nvim/msgpack_rpc/helpers.h" -#include "nvim/os/signal.h" -#include "nvim/os/rstream.h" -#include "nvim/os/wstream.h" -#include "nvim/os/job.h" -#include "nvim/vim.h" -#include "nvim/memory.h" -#include "nvim/misc2.h" -#include "nvim/ui.h" -#include "nvim/screen.h" -#include "nvim/terminal.h" - -#include "nvim/lib/klist.h" - -// event will be cleaned up after it gets processed -#define _destroy_event(x) // do nothing -KLIST_INIT(Event, Event, _destroy_event) - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/event.c.generated.h" -#endif -// deferred_events: Events that should be processed as the K_EVENT special key -// immediate_events: Events that should be processed after exiting libuv event -// loop(to avoid recursion), but before returning from -// `event_poll` -static klist_t(Event) *deferred_events = NULL, *immediate_events = NULL; -static int deferred_events_allowed = 0; - -void event_init(void) -{ - // Initialize the event queues - deferred_events = kl_init(Event); - immediate_events = kl_init(Event); - // early msgpack-rpc initialization - msgpack_rpc_init_method_table(); - msgpack_rpc_helpers_init(); - // Initialize input events - input_init(); - // Timer to wake the event loop if a timeout argument is passed to - // `event_poll` - // Signals - signal_init(); - // Jobs - job_init(); - // finish mspgack-rpc initialization - channel_init(); - server_init(); - terminal_init(); -} - -void event_teardown(void) -{ - if (!deferred_events) { - // Not initialized(possibly a --version invocation) - return; - } - - process_events_from(immediate_events); - process_events_from(deferred_events); - input_stop(); - channel_teardown(); - job_teardown(); - server_teardown(); - signal_teardown(); - terminal_teardown(); - - // this last `uv_run` will return after all handles are stopped, it will - // also take care of finishing any uv_close calls made by other *_teardown - // functions. - do { - uv_run(uv_default_loop(), UV_RUN_DEFAULT); - } while (uv_loop_close(uv_default_loop())); -} - -// Wait for some event -void event_poll(int ms) -{ - static int recursive = 0; - - if (recursive++) { - abort(); // Should not re-enter uv_run - } - - uv_run_mode run_mode = UV_RUN_ONCE; - uv_timer_t timer; - - if (ms > 0) { - uv_timer_init(uv_default_loop(), &timer); - // Use a repeating timeout of ms milliseconds to make sure - // we do not block indefinitely for I/O. - uv_timer_start(&timer, timer_cb, (uint64_t)ms, (uint64_t)ms); - } else if (ms == 0) { - // For ms == 0, we need to do a non-blocking event poll by - // setting the run mode to UV_RUN_NOWAIT. - run_mode = UV_RUN_NOWAIT; - } - - loop(run_mode); - - if (ms > 0) { - // Ensure the timer handle is closed and run the event loop - // once more to let libuv perform it's cleanup - uv_timer_stop(&timer); - uv_close((uv_handle_t *)&timer, NULL); - loop(UV_RUN_NOWAIT); - } - - recursive--; // Can re-enter uv_run now - - // In case this is run before event_init, don't process any events. - if (immediate_events) { - process_events_from(immediate_events); - } -} - -bool event_has_deferred(void) -{ - return deferred_events_allowed && !kl_empty(deferred_events); -} - -void event_enable_deferred(void) -{ - ++deferred_events_allowed; -} - -void event_disable_deferred(void) -{ - --deferred_events_allowed; -} - -// Queue an event -void event_push(Event event, bool deferred) -{ - // Sometimes libuv will run pending callbacks(timer for example) before - // blocking for a poll. If this happens and the callback pushes a event to one - // of the queues, the event would only be processed after the poll - // returns(user hits a key for example). To avoid this scenario, we call - // uv_stop when a event is enqueued. - uv_stop(uv_default_loop()); - kl_push(Event, deferred ? deferred_events : immediate_events, event); -} - -void event_process(void) -{ - process_events_from(deferred_events); -} - -static void process_events_from(klist_t(Event) *queue) -{ - while (!kl_empty(queue)) { - Event event = kl_shift(Event, queue); - event.handler(event); - } -} - -static void timer_cb(uv_timer_t *handle) -{ -} - -static void loop(uv_run_mode run_mode) -{ - DLOG("Enter event loop"); - uv_run(uv_default_loop(), run_mode); - DLOG("Exit event loop"); -} diff --git a/src/nvim/os/event.h b/src/nvim/os/event.h deleted file mode 100644 index db02b38c7f..0000000000 --- a/src/nvim/os/event.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef NVIM_OS_EVENT_H -#define NVIM_OS_EVENT_H - -#include <stdint.h> -#include <stdbool.h> - -#include "nvim/os/event_defs.h" -#include "nvim/os/job_defs.h" -#include "nvim/os/time.h" - -// Poll for events until a condition or timeout -#define event_poll_until(timeout, condition) \ - do { \ - int remaining = timeout; \ - uint64_t before = (remaining > 0) ? os_hrtime() : 0; \ - while (!(condition)) { \ - event_poll(remaining); \ - if (remaining == 0) { \ - break; \ - } else if (remaining > 0) { \ - uint64_t now = os_hrtime(); \ - remaining -= (int) ((now - before) / 1000000); \ - before = now; \ - if (remaining <= 0) { \ - break; \ - } \ - } \ - } \ - } while (0) - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/event.h.generated.h" -#endif - -#endif // NVIM_OS_EVENT_H diff --git a/src/nvim/os/event_defs.h b/src/nvim/os/event_defs.h deleted file mode 100644 index 2dd9403d9f..0000000000 --- a/src/nvim/os/event_defs.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NVIM_OS_EVENT_DEFS_H -#define NVIM_OS_EVENT_DEFS_H - -#include <stdbool.h> - -#include "nvim/os/job_defs.h" -#include "nvim/os/rstream_defs.h" - -typedef struct event Event; -typedef void (*event_handler)(Event event); - -struct event { - void *data; - event_handler handler; -}; - -#endif // NVIM_OS_EVENT_DEFS_H diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 726335bd9a..1449c56d59 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -6,7 +6,7 @@ #include "nvim/api/private/defs.h" #include "nvim/os/input.h" -#include "nvim/os/event.h" +#include "nvim/event/loop.h" #include "nvim/os/rstream_defs.h" #include "nvim/os/rstream.h" #include "nvim/ascii.h" @@ -115,7 +115,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt) } // If there are deferred events, return the keys directly - if (event_has_deferred()) { + if (loop_has_deferred_events(&loop)) { return push_event_key(buf, maxlen); } @@ -136,7 +136,7 @@ bool os_char_avail(void) void os_breakcheck(void) { if (!disable_breakcheck && !got_int) { - event_poll(0); + loop_poll_events(&loop, 0); } } @@ -285,7 +285,7 @@ static bool input_poll(int ms) prof_inchar_enter(); } - event_poll_until(ms, input_ready() || input_eof); + LOOP_POLL_EVENTS_UNTIL(&loop, ms, input_ready() || input_eof); if (do_profiling == PROF_YES && ms) { prof_inchar_exit(); @@ -362,7 +362,7 @@ static bool input_ready(void) { return typebuf_was_filled || // API call filled typeahead rbuffer_size(input_buffer) || // Input buffer filled - event_has_deferred(); // Events must be processed + loop_has_deferred_events(&loop); // Events must be processed } // Exit because of an input read error. diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index f9bde21361..7e90994fb3 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -3,6 +3,9 @@ #include <uv.h> +#include "nvim/event/loop.h" +#include "nvim/event/time.h" +#include "nvim/event/signal.h" #include "nvim/os/uv_helpers.h" #include "nvim/os/job.h" #include "nvim/os/job_defs.h" @@ -12,8 +15,6 @@ #include "nvim/os/rstream_defs.h" #include "nvim/os/wstream.h" #include "nvim/os/wstream_defs.h" -#include "nvim/os/event.h" -#include "nvim/os/event_defs.h" #include "nvim/os/time.h" #include "nvim/vim.h" #include "nvim/memory.h" @@ -45,8 +46,8 @@ Job *table[MAX_RUNNING_JOBS] = {NULL}; size_t stop_requests = 0; -uv_timer_t job_stop_timer; -uv_signal_t schld; +TimeWatcher job_stop_timer; +SignalWatcher schld; // Some helpers shared in this module @@ -59,9 +60,9 @@ uv_signal_t schld; void job_init(void) { uv_disable_stdio_inheritance(); - uv_timer_init(uv_default_loop(), &job_stop_timer); - uv_signal_init(uv_default_loop(), &schld); - uv_signal_start(&schld, chld_handler, SIGCHLD); + time_watcher_init(&loop, &job_stop_timer, NULL); + signal_watcher_init(&loop, &schld, NULL); + signal_watcher_start(&schld, chld_handler, SIGCHLD); } /// Releases job control resources and terminates running jobs @@ -78,11 +79,11 @@ void job_teardown(void) } // Wait until all jobs are closed - event_poll_until(-1, !stop_requests); - uv_signal_stop(&schld); - uv_close((uv_handle_t *)&schld, NULL); + LOOP_POLL_EVENTS_UNTIL(&loop, -1, !stop_requests); + signal_watcher_stop(&schld); + signal_watcher_close(&schld, NULL); // Close the timer - uv_close((uv_handle_t *)&job_stop_timer, NULL); + time_watcher_close(&job_stop_timer, NULL); } /// Tries to start a new job. @@ -152,7 +153,7 @@ Job *job_start(JobOptions opts, int *status) uv_close((uv_handle_t *)job->proc_stderr, close_cb); } process_close(job); - event_poll(0); + loop_poll_events(&loop, 0); // Manually invoke the close_cb to free the job resources *status = -1; return NULL; @@ -223,7 +224,7 @@ void job_stop(Job *job) // When there's at least one stop request pending, start a timer that // will periodically check if a signal should be send to a to the job DLOG("Starting job kill timer"); - uv_timer_start(&job_stop_timer, job_stop_timer_cb, 100, 100); + time_watcher_start(&job_stop_timer, job_stop_timer_cb, 100, 100); } } @@ -245,7 +246,7 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL // Increase refcount to stop the job from being freed before we have a // chance to get the status. job->refcount++; - event_poll_until(ms, + LOOP_POLL_EVENTS_UNTIL(&loop, ms, // Until... got_int || // interrupted by the user job->refcount == 1); // job exited @@ -259,9 +260,9 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL if (ms == -1) { // We can only return, if all streams/handles are closed and the job // exited. - event_poll_until(-1, job->refcount == 1); + LOOP_POLL_EVENTS_UNTIL(&loop, -1, job->refcount == 1); } else { - event_poll(0); + loop_poll_events(&loop, 0); } } @@ -379,7 +380,7 @@ JobOptions *job_opts(Job *job) /// Iterates the table, sending SIGTERM to stopped jobs and SIGKILL to those /// that didn't die from SIGTERM after a while(exit_timeout is 0). -static void job_stop_timer_cb(uv_timer_t *handle) +static void job_stop_timer_cb(TimeWatcher *watcher, void *data) { Job *job; uint64_t now = os_hrtime(); @@ -432,7 +433,7 @@ static void job_exited(Event event) process_close(job); } -static void chld_handler(uv_signal_t *handle, int signum) +static void chld_handler(SignalWatcher *watcher, int signum, void *data) { int stat = 0; int pid; @@ -458,7 +459,8 @@ static void chld_handler(uv_signal_t *handle, int signum) // don't enqueue more events when exiting process_close(job); } else { - event_push((Event) {.handler = job_exited, .data = job}, false); + loop_push_event(&loop, + (Event) {.handler = job_exited, .data = job}, false); } break; } diff --git a/src/nvim/os/job.h b/src/nvim/os/job.h index e0ca615626..ed102666d0 100644 --- a/src/nvim/os/job.h +++ b/src/nvim/os/job.h @@ -11,7 +11,7 @@ #include <stdbool.h> #include "nvim/os/rstream_defs.h" -#include "nvim/os/event_defs.h" +#include "nvim/os/job_defs.h" #include "nvim/os/wstream.h" #include "nvim/os/wstream_defs.h" diff --git a/src/nvim/os/job_private.h b/src/nvim/os/job_private.h index 983106d918..b90f2d0171 100644 --- a/src/nvim/os/job_private.h +++ b/src/nvim/os/job_private.h @@ -5,6 +5,7 @@ #include <uv.h> +#include "nvim/event/time.h" #include "nvim/os/rstream_defs.h" #include "nvim/os/wstream_defs.h" #include "nvim/os/pipe_process.h" @@ -43,7 +44,7 @@ struct job { extern Job *table[]; extern size_t stop_requests; -extern uv_timer_t job_stop_timer; +extern TimeWatcher job_stop_timer; static inline bool process_spawn(Job *job) { @@ -95,7 +96,7 @@ static inline void job_exit_callback(Job *job) if (stop_requests && !--stop_requests) { // Stop the timer if no more stop requests are pending DLOG("Stopping job kill timer"); - uv_timer_stop(&job_stop_timer); + time_watcher_stop(&job_stop_timer); } } diff --git a/src/nvim/os/pipe_process.c b/src/nvim/os/pipe_process.c index 2ac305e967..9980cf7c56 100644 --- a/src/nvim/os/pipe_process.c +++ b/src/nvim/os/pipe_process.c @@ -9,6 +9,8 @@ #include "nvim/os/job_private.h" #include "nvim/os/pipe_process.h" #include "nvim/memory.h" +#include "nvim/vim.h" +#include "nvim/globals.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/pipe_process.c.generated.h" @@ -46,19 +48,19 @@ void pipe_process_init(Job *job) handle_set_job((uv_handle_t *)&pipeproc->proc, job); if (job->opts.writable) { - uv_pipe_init(uv_default_loop(), &pipeproc->proc_stdin, 0); + uv_pipe_init(&loop.uv, &pipeproc->proc_stdin, 0); pipeproc->stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE; pipeproc->stdio[0].data.stream = (uv_stream_t *)&pipeproc->proc_stdin; } if (job->opts.stdout_cb) { - uv_pipe_init(uv_default_loop(), &pipeproc->proc_stdout, 0); + uv_pipe_init(&loop.uv, &pipeproc->proc_stdout, 0); pipeproc->stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE; pipeproc->stdio[1].data.stream = (uv_stream_t *)&pipeproc->proc_stdout; } if (job->opts.stderr_cb) { - uv_pipe_init(uv_default_loop(), &pipeproc->proc_stderr, 0); + uv_pipe_init(&loop.uv, &pipeproc->proc_stderr, 0); pipeproc->stdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE; pipeproc->stdio[2].data.stream = (uv_stream_t *)&pipeproc->proc_stderr; } @@ -81,7 +83,7 @@ bool pipe_process_spawn(Job *job) { UvProcess *pipeproc = job->process; - if (uv_spawn(uv_default_loop(), &pipeproc->proc, &pipeproc->proc_opts) != 0) { + if (uv_spawn(&loop.uv, &pipeproc->proc, &pipeproc->proc_opts) != 0) { return false; } diff --git a/src/nvim/os/pty_process.c b/src/nvim/os/pty_process.c index ff0bcfb6de..ca74ebfddd 100644 --- a/src/nvim/os/pty_process.c +++ b/src/nvim/os/pty_process.c @@ -26,6 +26,8 @@ #include "nvim/os/job_private.h" #include "nvim/os/pty_process.h" #include "nvim/memory.h" +#include "nvim/vim.h" +#include "nvim/globals.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/pty_process.c.generated.h" @@ -43,17 +45,17 @@ void pty_process_init(Job *job) FUNC_ATTR_NONNULL_ALL ptyproc->tty_fd = -1; if (job->opts.writable) { - uv_pipe_init(uv_default_loop(), &ptyproc->proc_stdin, 0); + uv_pipe_init(&loop.uv, &ptyproc->proc_stdin, 0); ptyproc->proc_stdin.data = NULL; } if (job->opts.stdout_cb) { - uv_pipe_init(uv_default_loop(), &ptyproc->proc_stdout, 0); + uv_pipe_init(&loop.uv, &ptyproc->proc_stdout, 0); ptyproc->proc_stdout.data = NULL; } if (job->opts.stderr_cb) { - uv_pipe_init(uv_default_loop(), &ptyproc->proc_stderr, 0); + uv_pipe_init(&loop.uv, &ptyproc->proc_stderr, 0); ptyproc->proc_stderr.data = NULL; } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index af84288f0f..dd91c2777e 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -120,7 +120,7 @@ void rstream_set_file(RStream *rstream, uv_file file) // in chunks of rstream->buffer_size, giving time for other events to // be processed between reads. rstream->fread_idle = xmalloc(sizeof(uv_idle_t)); - uv_idle_init(uv_default_loop(), rstream->fread_idle); + uv_idle_init(&loop.uv, rstream->fread_idle); rstream->fread_idle->data = NULL; handle_set_rstream((uv_handle_t *)rstream->fread_idle, rstream); } else { @@ -128,7 +128,7 @@ void rstream_set_file(RStream *rstream, uv_file file) assert(rstream->file_type == UV_NAMED_PIPE || rstream->file_type == UV_TTY); rstream->stream = xmalloc(sizeof(uv_pipe_t)); - uv_pipe_init(uv_default_loop(), (uv_pipe_t *)rstream->stream, 0); + uv_pipe_init(&loop.uv, (uv_pipe_t *)rstream->stream, 0); uv_pipe_open((uv_pipe_t *)rstream->stream, file); rstream->stream->data = NULL; handle_set_rstream((uv_handle_t *)rstream->stream, rstream); @@ -224,7 +224,7 @@ static void fread_idle_cb(uv_idle_t *handle) // Synchronous read uv_fs_read( - uv_default_loop(), + &loop.uv, &req, rstream->fd, &rstream->uvbuf, diff --git a/src/nvim/os/rstream.h b/src/nvim/os/rstream.h index 3e24724573..7da77b33fa 100644 --- a/src/nvim/os/rstream.h +++ b/src/nvim/os/rstream.h @@ -4,7 +4,6 @@ #include <stdbool.h> #include <stdint.h> #include <uv.h> -#include "nvim/os/event_defs.h" #include "nvim/os/rstream_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 48174533a6..9c0d5fca67 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -8,7 +8,7 @@ #include "nvim/ascii.h" #include "nvim/lib/kvec.h" #include "nvim/log.h" -#include "nvim/os/event.h" +#include "nvim/event/loop.h" #include "nvim/os/job.h" #include "nvim/os/rstream.h" #include "nvim/os/shell.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index f824543003..6de3435c4c 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -11,12 +11,13 @@ #include "nvim/memory.h" #include "nvim/misc1.h" #include "nvim/misc2.h" +#include "nvim/event/signal.h" #include "nvim/os/signal.h" -#include "nvim/os/event.h" +#include "nvim/event/loop.h" -static uv_signal_t spipe, shup, squit, sterm; +static SignalWatcher spipe, shup, squit, sterm; #ifdef SIGPWR -static uv_signal_t spwr; +static SignalWatcher spwr; #endif static bool rejecting_deadly; @@ -27,40 +28,40 @@ static bool rejecting_deadly; void signal_init(void) { - uv_signal_init(uv_default_loop(), &spipe); - uv_signal_init(uv_default_loop(), &shup); - uv_signal_init(uv_default_loop(), &squit); - uv_signal_init(uv_default_loop(), &sterm); - uv_signal_start(&spipe, signal_cb, SIGPIPE); - uv_signal_start(&shup, signal_cb, SIGHUP); - uv_signal_start(&squit, signal_cb, SIGQUIT); - uv_signal_start(&sterm, signal_cb, SIGTERM); + signal_watcher_init(&loop, &spipe, NULL); + signal_watcher_init(&loop, &shup, NULL); + signal_watcher_init(&loop, &squit, NULL); + signal_watcher_init(&loop, &sterm, NULL); + signal_watcher_start(&spipe, on_signal, SIGPIPE); + signal_watcher_start(&shup, on_signal, SIGHUP); + signal_watcher_start(&squit, on_signal, SIGQUIT); + signal_watcher_start(&sterm, on_signal, SIGTERM); #ifdef SIGPWR - uv_signal_init(uv_default_loop(), &spwr); - uv_signal_start(&spwr, signal_cb, SIGPWR); + signal_watcher_init(&loop, &spwr, NULL); + signal_watcher_start(&spwr, on_signal, SIGPWR); #endif } void signal_teardown(void) { signal_stop(); - uv_close((uv_handle_t *)&spipe, NULL); - uv_close((uv_handle_t *)&shup, NULL); - uv_close((uv_handle_t *)&squit, NULL); - uv_close((uv_handle_t *)&sterm, NULL); + signal_watcher_close(&spipe, NULL); + signal_watcher_close(&shup, NULL); + signal_watcher_close(&squit, NULL); + signal_watcher_close(&sterm, NULL); #ifdef SIGPWR - uv_close((uv_handle_t *)&spwr, NULL); + signal_watcher_close(&spwr, NULL); #endif } void signal_stop(void) { - uv_signal_stop(&spipe); - uv_signal_stop(&shup); - uv_signal_stop(&squit); - uv_signal_stop(&sterm); + signal_watcher_stop(&spipe); + signal_watcher_stop(&shup); + signal_watcher_stop(&squit); + signal_watcher_stop(&sterm); #ifdef SIGPWR - uv_signal_stop(&spwr); + signal_watcher_stop(&spwr); #endif } @@ -111,10 +112,10 @@ static void deadly_signal(int signum) preserve_exit(); } -static void signal_cb(uv_signal_t *handle, int signum) +static void on_signal(SignalWatcher *handle, int signum, void *data) { assert(signum >= 0); - event_push((Event) { + loop_push_event(&loop, (Event) { .handler = on_signal_event, .data = (void *)(uintptr_t)signum }, false); diff --git a/src/nvim/os/signal.h b/src/nvim/os/signal.h index 927437b2db..5d8cc6f661 100644 --- a/src/nvim/os/signal.h +++ b/src/nvim/os/signal.h @@ -1,8 +1,6 @@ #ifndef NVIM_OS_SIGNAL_H #define NVIM_OS_SIGNAL_H -#include "nvim/os/event_defs.h" - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/signal.h.generated.h" #endif diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 590dfba797..6b5d4359db 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -7,7 +7,7 @@ #include <uv.h> #include "nvim/os/time.h" -#include "nvim/os/event.h" +#include "nvim/event/loop.h" #include "nvim/vim.h" static uv_mutex_t delay_mutex; @@ -43,7 +43,7 @@ void os_delay(uint64_t milliseconds, bool ignoreinput) if (milliseconds > INT_MAX) { milliseconds = INT_MAX; } - event_poll_until((int)milliseconds, got_int); + LOOP_POLL_EVENTS_UNTIL(&loop, (int)milliseconds, got_int); } else { os_microdelay(milliseconds * 1000); } diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c index 73896c381d..7f5191947a 100644 --- a/src/nvim/os/wstream.c +++ b/src/nvim/os/wstream.c @@ -103,7 +103,7 @@ void wstream_set_file(WStream *wstream, uv_file file) assert(uv_guess_handle(file) == UV_NAMED_PIPE || uv_guess_handle(file) == UV_TTY); wstream->stream = xmalloc(sizeof(uv_pipe_t)); - uv_pipe_init(uv_default_loop(), (uv_pipe_t *)wstream->stream, 0); + uv_pipe_init(&loop.uv, (uv_pipe_t *)wstream->stream, 0); uv_pipe_open((uv_pipe_t *)wstream->stream, file); wstream->stream->data = NULL; handle_set_wstream((uv_handle_t *)wstream->stream, wstream); |