ui_bridge.h
Go to the documentation of this file.
1 // Bridge for communication between a UI thread and nvim core.
2 // Used by the built-in TUI and libnvim-based UIs.
3 #ifndef NVIM_UI_BRIDGE_H
4 #define NVIM_UI_BRIDGE_H
5 
6 #include <uv.h>
7 
8 #include "nvim/ui.h"
9 #include "nvim/event/defs.h"
10 
12 typedef void(*ui_main_fn)(UIBridgeData *bridge, UI *ui);
14  UI bridge; // actual UI passed to ui_attach
15  UI *ui; // UI pointer that will have its callback called in
16  // another thread
18  uv_thread_t ui_thread;
20  uv_mutex_t mutex;
21  uv_cond_t cond;
22  // When the UI thread is called, the main thread will suspend until
23  // the call returns. This flag is used as a condition for the main
24  // thread to continue.
25  bool ready;
26  // When a stop request is sent from the main thread, it must wait until the UI
27  // thread finishes handling all events. This flag is set by the UI thread as a
28  // signal that it will no longer send messages to the main thread.
29  bool stopped;
30 };
31 
32 #define CONTINUE(b) \
33  do { \
34  UIBridgeData *d = (UIBridgeData *)b; \
35  uv_mutex_lock(&d->mutex); \
36  d->ready = true; \
37  uv_cond_signal(&d->cond); \
38  uv_mutex_unlock(&d->mutex); \
39  } while (0)
40 
41 
42 #ifdef INCLUDE_GENERATED_DECLARATIONS
43 # include "ui_bridge.h.generated.h"
44 #endif
45 #endif // NVIM_UI_BRIDGE_H
uv_mutex_t mutex
Definition: ui_bridge.h:20
void(* ui_main_fn)(UIBridgeData *bridge, UI *ui)
Definition: ui_bridge.h:12
Definition: ui.h:37
bool stopped
Definition: ui_bridge.h:29
Definition: ui_bridge.h:13
void(* event_scheduler)(Event event, void *data)
Definition: defs.h:14
uv_thread_t ui_thread
Definition: ui_bridge.h:18
bool ready
Definition: ui_bridge.h:25
event_scheduler scheduler
Definition: ui_bridge.h:17
ui_main_fn ui_main
Definition: ui_bridge.h:19
UI bridge
Definition: ui_bridge.h:14
uv_cond_t cond
Definition: ui_bridge.h:21
UI * ui
Definition: ui_bridge.h:15