mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 23:48:32 +00:00
ui: Implement module for thread-safe communication with U
The ui_bridge.c module implements a surrogate UI that forwards calls to another thread.
This commit is contained in:
40
src/nvim/ui_bridge.h
Normal file
40
src/nvim/ui_bridge.h
Normal file
@@ -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
|
Reference in New Issue
Block a user