diff options
| author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-07-17 00:46:34 -0300 |
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-07-17 00:46:34 -0300 |
| commit | 883b78d29864f39b8032468c4374766dad7d142f (patch) | |
| tree | b555f3a48c08862c07ef7518a8ba6c8fa58c1aee /src/nvim/event/loop.h | |
| parent | d88c93acf390ea9d5e8674283927cff60fb41e0d (diff) | |
| parent | aa9cb48bf08af14068178619414590254b263882 (diff) | |
| download | rneovim-883b78d29864f39b8032468c4374766dad7d142f.tar.gz rneovim-883b78d29864f39b8032468c4374766dad7d142f.tar.bz2 rneovim-883b78d29864f39b8032468c4374766dad7d142f.zip | |
Merge PR #2980 'Refactor event loop layer'
Helped-by: oni-link <knil.ino@gmail.com>
Reviewed-by: oni-link <knil.ino@gmail.com>
Reviewed-by: Scott Prager <splinterofchaos@gmail.com>
Diffstat (limited to 'src/nvim/event/loop.h')
| -rw-r--r-- | src/nvim/event/loop.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h new file mode 100644 index 0000000000..5eb4d32ca8 --- /dev/null +++ b/src/nvim/event/loop.h @@ -0,0 +1,59 @@ +#ifndef NVIM_EVENT_LOOP_H +#define NVIM_EVENT_LOOP_H + +#include <stdint.h> + +#include <uv.h> + +#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; +}; + +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; + klist_t(WatcherPtr) *children; + uv_signal_t children_watcher; + uv_timer_t children_kill_timer; + size_t children_stop_requests; +} Loop; + +// Poll for events until a condition or timeout +#define LOOP_POLL_EVENTS_UNTIL(loop, timeout, condition) \ + do { \ + int remaining = timeout; \ + uint64_t before = (remaining > 0) ? os_hrtime() : 0; \ + while (!(condition)) { \ + loop_poll_events(loop, 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 "event/loop.h.generated.h" +#endif + +#endif // NVIM_EVENT_LOOP_H |