loop.h
Go to the documentation of this file.
1 #ifndef NVIM_EVENT_LOOP_H
2 #define NVIM_EVENT_LOOP_H
3 
4 #include <stdint.h>
5 #include <uv.h>
6 
8 #include "nvim/lib/klist.h"
9 #include "nvim/os/time.h"
10 
11 typedef void *WatcherPtr;
12 
13 #define _noop(x)
15 
16 typedef struct loop {
17  uv_loop_t uv;
20  // Immediate events:
21  // "Processed after exiting uv_run() (to avoid recursion), but before
22  // returning from loop_poll_events()." 502aee690c98
23  // Practical consequence (for main_loop): these events are processed by
24  // state_enter()..os_inchar()
25  // whereas "regular" events (main_loop.events) are processed by
26  // state_enter()..VimState.execute()
27  // But state_enter()..os_inchar() can be "too early" if you want the event
28  // to trigger UI updates and other user-activity-related side-effects.
30 
31  // used by process/job-control subsystem
32  klist_t(WatcherPtr) *children;
33  uv_signal_t children_watcher;
34  uv_timer_t children_kill_timer;
35 
36  // generic timer, used by loop_poll_events()
37  uv_timer_t poll_timer;
38 
39  uv_async_t async;
40  uv_mutex_t mutex;
41  int recursive;
42 } Loop;
43 
44 #define CREATE_EVENT(multiqueue, handler, argc, ...) \
45  do { \
46  if (multiqueue) { \
47  multiqueue_put((multiqueue), (handler), argc, __VA_ARGS__); \
48  } else { \
49  void *argv[argc] = { __VA_ARGS__ }; \
50  (handler)(argv); \
51  } \
52  } while (0)
53 
54 // -V:LOOP_PROCESS_EVENTS_UNTIL:547
55 
56 // Poll for events until a condition or timeout
57 #define LOOP_PROCESS_EVENTS_UNTIL(loop, multiqueue, timeout, condition) \
58  do { \
59  int remaining = timeout; \
60  uint64_t before = (remaining > 0) ? os_hrtime() : 0; \
61  while (!(condition)) { \
62  LOOP_PROCESS_EVENTS(loop, multiqueue, remaining); \
63  if (remaining == 0) { \
64  break; \
65  } else if (remaining > 0) { \
66  uint64_t now = os_hrtime(); \
67  remaining -= (int)((now - before) / 1000000); \
68  before = now; \
69  if (remaining <= 0) { \
70  break; \
71  } \
72  } \
73  } \
74  } while (0)
75 
76 #define LOOP_PROCESS_EVENTS(loop, multiqueue, timeout) \
77  do { \
78  if (multiqueue && !multiqueue_empty(multiqueue)) { \
79  multiqueue_process_events(multiqueue); \
80  } else { \
81  loop_poll_events(loop, timeout); \
82  } \
83  } while (0)
84 
85 
86 #ifdef INCLUDE_GENERATED_DECLARATIONS
87 # include "event/loop.h.generated.h"
88 #endif
89 
90 #endif // NVIM_EVENT_LOOP_H
klist.h
time.h
loop::mutex
uv_mutex_t mutex
Definition: loop.h:40
loop::fast_events
MultiQueue * fast_events
Definition: loop.h:29
loop::recursive
int recursive
Definition: loop.h:41
KLIST_INIT
#define KLIST_INIT(name, kltype_t, kmpfree_t)
Definition: klist.h:75
loop::thread_events
MultiQueue * thread_events
Definition: loop.h:19
loop::async
uv_async_t async
Definition: loop.h:39
Loop
struct loop Loop
loop::children_kill_timer
uv_timer_t children_kill_timer
Definition: loop.h:34
WatcherPtr
void * WatcherPtr
Definition: loop.h:11
multiqueue
Definition: multiqueue.c:71
loop::children_watcher
uv_signal_t children_watcher
Definition: loop.h:33
klist_t
#define klist_t(name)
Definition: klist.h:127
_noop
#define _noop(x)
Definition: loop.h:13
loop::poll_timer
uv_timer_t poll_timer
Definition: loop.h:37
multiqueue.h
loop::events
MultiQueue * events
Definition: loop.h:18
loop
Definition: loop.h:16
loop::uv
uv_loop_t uv
Definition: loop.h:17