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.
This commit is contained in:
Thiago de Arruda
2015-07-16 23:10:04 -03:00
parent 9e42ef4e13
commit 991d3ec1e6
38 changed files with 499 additions and 338 deletions

View File

@@ -67,7 +67,8 @@
#include "nvim/ex_cmds.h"
#include "nvim/window.h"
#include "nvim/fileio.h"
#include "nvim/os/event.h"
#include "nvim/event/loop.h"
#include "nvim/event/time.h"
#include "nvim/api/private/helpers.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -80,7 +81,7 @@
// of data.
#define REFRESH_DELAY 10
static uv_timer_t refresh_timer;
static TimeWatcher refresh_timer;
static bool refresh_pending = false;
typedef struct {
@@ -150,7 +151,7 @@ static VTermColor default_vt_bg_rgb;
void terminal_init(void)
{
invalidated_terminals = pmap_new(ptr_t)();
uv_timer_init(uv_default_loop(), &refresh_timer);
time_watcher_init(&loop, &refresh_timer, NULL);
// initialize a rgb->color index map for cterm attributes(VTermScreenCell
// only has RGB information and we need color indexes for terminal UIs)
@@ -175,8 +176,8 @@ void terminal_init(void)
void terminal_teardown(void)
{
uv_timer_stop(&refresh_timer);
uv_close((uv_handle_t *)&refresh_timer, NULL);
time_watcher_stop(&refresh_timer);
time_watcher_close(&refresh_timer, NULL);
pmap_free(ptr_t)(invalidated_terminals);
map_free(int, int)(color_indexes);
}
@@ -353,13 +354,13 @@ void terminal_enter(bool process_deferred)
while (term->buf == curbuf) {
if (process_deferred) {
event_enable_deferred();
loop_enable_deferred_events(&loop);
}
c = safe_vgetc();
if (process_deferred) {
event_disable_deferred();
loop_disable_deferred_events(&loop);
}
switch (c) {
@@ -380,7 +381,7 @@ void terminal_enter(bool process_deferred)
break;
case K_EVENT:
event_process();
loop_process_event(&loop);
break;
case Ctrl_N:
@@ -877,16 +878,16 @@ static void invalidate_terminal(Terminal *term, int start_row, int end_row)
pmap_put(ptr_t)(invalidated_terminals, term, NULL);
if (!refresh_pending) {
uv_timer_start(&refresh_timer, refresh_timer_cb, REFRESH_DELAY, 0);
time_watcher_start(&refresh_timer, refresh_timer_cb, REFRESH_DELAY, 0);
refresh_pending = true;
}
}
// libuv timer callback. This will enqueue on_refresh to be processed as an
// event.
static void refresh_timer_cb(uv_timer_t *handle)
static void refresh_timer_cb(TimeWatcher *watcher, void *data)
{
event_push((Event) {.handler = on_refresh}, false);
loop_push_event(&loop, (Event) {.handler = on_refresh}, false);
refresh_pending = false;
}