diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-08-13 12:20:53 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-08-13 12:20:53 -0300 |
commit | a94a68145b3c607d1e58f708ded8fe625c9973d5 (patch) | |
tree | 2d69f4f3a06f0ac5a4e936ec40bde81a26cf2b53 /src/nvim/event/loop.h | |
parent | 6bf322c6ff190b9f10c5286b3ae6fceedfbddb61 (diff) | |
parent | f1de097dbb236ea400150f80b909407ca9af7441 (diff) | |
download | rneovim-a94a68145b3c607d1e58f708ded8fe625c9973d5.tar.gz rneovim-a94a68145b3c607d1e58f708ded8fe625c9973d5.tar.bz2 rneovim-a94a68145b3c607d1e58f708ded8fe625c9973d5.zip |
Merge PR #3029 'Refactor event processing architecture'
Helped-by: oni-link <knil.ino@gmail.com>
Reviewed-by: oni-link <knil.ino@gmail.com>
Diffstat (limited to 'src/nvim/event/loop.h')
-rw-r--r-- | src/nvim/event/loop.h | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h index 5eb4d32ca8..9212a45aa4 100644 --- a/src/nvim/event/loop.h +++ b/src/nvim/event/loop.h @@ -7,38 +7,39 @@ #include "nvim/lib/klist.h" #include "nvim/os/time.h" - -typedef struct event Event; -typedef void (*event_handler)(Event event); - -struct event { - void *data; - event_handler handler; -}; +#include "nvim/event/queue.h" typedef void * WatcherPtr; #define _noop(x) KLIST_INIT(WatcherPtr, WatcherPtr, _noop) -KLIST_INIT(Event, Event, _noop) typedef struct loop { uv_loop_t uv; - klist_t(Event) *deferred_events, *immediate_events; - int deferred_events_allowed; + Queue *events, *fast_events; klist_t(WatcherPtr) *children; uv_signal_t children_watcher; - uv_timer_t children_kill_timer; + uv_timer_t children_kill_timer, poll_timer; size_t children_stop_requests; } Loop; +#define CREATE_EVENT(queue, handler, argc, ...) \ + do { \ + if (queue) { \ + queue_put((queue), (handler), argc, __VA_ARGS__); \ + } else { \ + void *argv[argc] = {__VA_ARGS__}; \ + (handler)(argv); \ + } \ + } while (0) + // Poll for events until a condition or timeout -#define LOOP_POLL_EVENTS_UNTIL(loop, timeout, condition) \ +#define LOOP_PROCESS_EVENTS_UNTIL(loop, queue, timeout, condition) \ do { \ int remaining = timeout; \ uint64_t before = (remaining > 0) ? os_hrtime() : 0; \ while (!(condition)) { \ - loop_poll_events(loop, remaining); \ + LOOP_PROCESS_EVENTS(loop, queue, remaining); \ if (remaining == 0) { \ break; \ } else if (remaining > 0) { \ @@ -52,6 +53,16 @@ typedef struct loop { } \ } while (0) +#define LOOP_PROCESS_EVENTS(loop, queue, timeout) \ + do { \ + if (queue && !queue_empty(queue)) { \ + queue_process_events(queue); \ + } else { \ + loop_poll_events(loop, timeout); \ + } \ + } while (0) + + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/loop.h.generated.h" #endif |