aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ui_bridge.h
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-09-07 07:47:17 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-09-07 07:47:17 -0300
commitbb46cc2c9ce9a36f19df5c29a403c1feb4dbdf88 (patch)
tree499d8bcf29973994fbcbdc0b19bd9eb0a67ce726 /src/nvim/ui_bridge.h
parentf39ac698241885137e77efa4edeee7be21dd8deb (diff)
parenteb001a4abd2fbc740547c127807b2fc8367cc187 (diff)
downloadrneovim-bb46cc2c9ce9a36f19df5c29a403c1feb4dbdf88.tar.gz
rneovim-bb46cc2c9ce9a36f19df5c29a403c1feb4dbdf88.tar.bz2
rneovim-bb46cc2c9ce9a36f19df5c29a403c1feb4dbdf88.zip
Merge PR #3246 'Run builtin TUI in a another thread'
Diffstat (limited to 'src/nvim/ui_bridge.h')
-rw-r--r--src/nvim/ui_bridge.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/ui_bridge.h b/src/nvim/ui_bridge.h
new file mode 100644
index 0000000000..76e9e27989
--- /dev/null
+++ b/src/nvim/ui_bridge.h
@@ -0,0 +1,40 @@
+// Bridge used for communication between a builtin UI thread and nvim core
+#ifndef NVIM_UI_BRIDGE_H
+#define NVIM_UI_BRIDGE_H
+
+#include <uv.h>
+
+#include "nvim/ui.h"
+#include "nvim/event/defs.h"
+
+typedef struct ui_bridge_data UIBridgeData;
+typedef void(*ui_main_fn)(UIBridgeData *bridge, UI *ui);
+struct ui_bridge_data {
+ UI bridge; // actual UI passed to ui_attach
+ UI *ui; // UI pointer that will have it's callback called in
+ // another thread
+ event_scheduler scheduler;
+ uv_thread_t ui_thread;
+ ui_main_fn ui_main;
+ uv_mutex_t mutex;
+ uv_cond_t cond;
+ // When the UI thread is called, the main thread will suspend until
+ // the call returns. This flag is used as a condition for the main
+ // thread to continue.
+ bool ready;
+};
+
+#define CONTINUE(b) \
+ do { \
+ UIBridgeData *d = (UIBridgeData *)b; \
+ uv_mutex_lock(&d->mutex); \
+ d->ready = true; \
+ uv_cond_signal(&d->cond); \
+ uv_mutex_unlock(&d->mutex); \
+ } while (0)
+
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "ui_bridge.h.generated.h"
+#endif
+#endif // NVIM_UI_BRIDGE_H