From 9c2f4ce20d4ab36b17887ae927bab73432565515 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 26 Sep 2016 19:31:26 +0200 Subject: doc: minor comment tweaks --- src/nvim/diff.c | 6 ++---- src/nvim/event/queue.c | 14 +++++++------- src/nvim/ex_cmds.c | 14 +++++--------- src/nvim/globals.h | 6 +++--- src/nvim/os/shell.c | 4 ++-- src/nvim/rbuffer.h | 2 +- src/nvim/tui/tui.c | 2 ++ src/nvim/ui_bridge.c | 4 ++-- src/nvim/ui_bridge.h | 2 +- 9 files changed, 25 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ef5acf4845..f7b96ba3e1 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -906,8 +906,7 @@ void ex_diffpatch(exarg_T *eap) eval_patch((char *) tmp_orig, (char *) eap->arg, (char *) tmp_new); #endif // ifdef UNIX } else { - // Build the patch command and execute it. Ignore errors. Switch to - // cooked mode to allow the user to respond to prompts. + // Build the patch command and execute it. Ignore errors. #ifdef UNIX vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", tmp_new, tmp_orig, fullname != NULL ? fullname : eap->arg); @@ -915,8 +914,7 @@ void ex_diffpatch(exarg_T *eap) vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", tmp_new, tmp_orig, eap->arg); #endif // ifdef UNIX - // Avoid ShellCmdPost stuff - block_autocmds(); + block_autocmds(); // Avoid ShellCmdPost stuff (void)call_shell(buf, kShellOptFilter, NULL); unblock_autocmds(); } diff --git a/src/nvim/event/queue.c b/src/nvim/event/queue.c index c5ef22d426..ee224b0a25 100644 --- a/src/nvim/event/queue.c +++ b/src/nvim/event/queue.c @@ -8,7 +8,7 @@ // - removing a node from a child queue will remove the corresponding link node // in the parent queue // -// These properties allow neovim to organize and process events from different +// These properties allow Nvim to organize and process events from different // sources with a certain degree of control. Here's how the queue is used: // // +----------------+ @@ -26,20 +26,20 @@ // +-----------+ +-----------+ +---------+ +---------+ // // -// In the above diagram, the lower boxes represents event emitters, each with -// it's own private queue that have the event loop queue as the parent. +// The lower boxes represents event emitters, each with its own private queue +// having the event loop queue as the parent. // // When idle, the main loop spins the event loop which queues events from many -// sources(channels, jobs, user...). Each event emitter pushes events to its own +// sources (channels, jobs, user...). Each event emitter pushes events to its // private queue which is propagated to the event loop queue. When the main loop // consumes an event, the corresponding event is removed from the emitter's // queue. // // The main reason for this queue hierarchy is to allow focusing on a single // event emitter while blocking the main loop. For example, if the `jobwait` -// vimscript function is called on job1, the main loop will temporarily stop -// polling the event loop queue and poll job1 queue instead. Same with channels, -// when calling `rpcrequest`, we want to temporarily stop processing events from +// VimL function is called on job1, the main loop will temporarily stop polling +// the event loop queue and poll job1 queue instead. Same with channels, when +// calling `rpcrequest` we want to temporarily stop processing events from // other sources and focus on a specific channel. #include diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c36c3a7b0e..0226499e78 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1154,15 +1154,11 @@ static void do_filter( } read_linecount = curbuf->b_ml.ml_line_count; - /* - * When call_shell() fails wait_return() is called to give the user a - * chance to read the error messages. Otherwise errors are ignored, so you - * can see the error messages from the command that appear on stdout; use - * 'u' to fix the text - * Switch to cooked mode when not redirecting stdin, avoids that something - * like ":r !cat" hangs. - * Pass on the kShellDoOut flag when the output is being redirected. - */ + // When call_shell() fails wait_return() is called to give the user a chance + // to read the error messages. Otherwise errors are ignored, so you can see + // the error messages from the command that appear on stdout; use 'u' to fix + // the text. + // Pass on the kShellDoOut flag when the output is being redirected. if (call_shell( cmd_buf, kShellOptFilter | shell_flags, diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 57d12d396e..87fb928b30 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -927,9 +927,9 @@ EXTERN FILE *scriptin[NSCRIPT]; /* streams to read script from */ EXTERN int curscript INIT(= 0); /* index in scriptin[] */ EXTERN FILE *scriptout INIT(= NULL); /* stream to write script to */ -/* volatile because it is used in signal handler catch_sigint(). */ -EXTERN volatile int got_int INIT(= FALSE); /* set to TRUE when interrupt - signal occurred */ +// volatile because it is used in a signal handler. +EXTERN volatile int got_int INIT(= false); // set to true when interrupt + // signal occurred EXTERN int bangredo INIT(= FALSE); /* set to TRUE with ! command */ EXTERN int searchcmdlen; /* length of previous search cmd */ EXTERN int reg_do_extmatch INIT(= 0); /* Used when compiling regexp: diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 661b12accc..617a505367 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -162,7 +162,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) /// @param input The input to the shell (NULL for no input), passed to the /// stdin of the resulting process. /// @param len The length of the input buffer (not used if `input` == NULL) -/// @param[out] output A pointer to to a location where the output will be +/// @param[out] output Pointer to a location where the output will be /// allocated and stored. Will point to NULL if the shell /// command did not output anything. If NULL is passed, /// the shell output will be ignored. @@ -227,7 +227,7 @@ static int do_os_system(char **argv, // We want to deal with stream events as fast a possible while queueing // process events, so reset everything to NULL. It prevents closing the - // streams while there's still data in the OS buffer(due to the process + // streams while there's still data in the OS buffer (due to the process // exiting before all data is read). if (input != NULL) { proc->in->events = NULL; diff --git a/src/nvim/rbuffer.h b/src/nvim/rbuffer.h index 454972c69d..a8dfcac580 100644 --- a/src/nvim/rbuffer.h +++ b/src/nvim/rbuffer.h @@ -1,4 +1,4 @@ -// Ring buffer implementation. This is basically an array that wraps read/write +// Specialized ring buffer. This is basically an array that wraps read/write // pointers around the memory region. It should be more efficient than the old // RBuffer which required memmove() calls to relocate read/write positions. // diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index fc2a2604d6..4ec567a61b 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1,3 +1,5 @@ +// Terminal UI functions. Invoked (by ui_bridge.c) on the TUI thread. + #include #include #include diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 34b95baf6c..28c7144784 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -1,5 +1,5 @@ -// FIXME(tarruda): This module is very repetitive. It might be a good idea to -// automatically generate it with a lua script during build +// UI wrapper for the built-in TUI. Sends UI requests to the TUI thread. + #include #include #include diff --git a/src/nvim/ui_bridge.h b/src/nvim/ui_bridge.h index 561ddb6b24..45fd0873b4 100644 --- a/src/nvim/ui_bridge.h +++ b/src/nvim/ui_bridge.h @@ -11,7 +11,7 @@ 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 + UI *ui; // UI pointer that will have its callback called in // another thread event_scheduler scheduler; uv_thread_t ui_thread; -- cgit From beb2e4f095583af09ebe9c66e3bf453b61511f23 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 28 Sep 2016 03:11:15 +0200 Subject: tui: Move ui_bridge module to tui/ namespace. --- src/nvim/tui/tui.c | 6 +- src/nvim/tui/ui_bridge.c | 369 +++++++++++++++++++++++++++++++++++++++++++++++ src/nvim/tui/ui_bridge.h | 44 ++++++ src/nvim/ui_bridge.c | 369 ----------------------------------------------- src/nvim/ui_bridge.h | 44 ------ 5 files changed, 416 insertions(+), 416 deletions(-) create mode 100644 src/nvim/tui/ui_bridge.c create mode 100644 src/nvim/tui/ui_bridge.h delete mode 100644 src/nvim/ui_bridge.c delete mode 100644 src/nvim/ui_bridge.h (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 4ec567a61b..6f90742928 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -19,13 +19,13 @@ #include "nvim/api/private/helpers.h" #include "nvim/event/loop.h" #include "nvim/event/signal.h" -#include "nvim/tui/tui.h" -#include "nvim/tui/input.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/strings.h" #include "nvim/ugrid.h" -#include "nvim/ui_bridge.h" +#include "nvim/tui/input.h" +#include "nvim/tui/tui.h" +#include "nvim/tui/ui_bridge.h" // Space reserved in the output buffer to restore the cursor to normal when // flushing. No existing terminal will require 32 bytes to do that. diff --git a/src/nvim/tui/ui_bridge.c b/src/nvim/tui/ui_bridge.c new file mode 100644 index 0000000000..48f4b1bda6 --- /dev/null +++ b/src/nvim/tui/ui_bridge.c @@ -0,0 +1,369 @@ +// UI wrapper for the built-in TUI. Sends UI requests to the TUI thread. + +#include +#include +#include +#include + +#include "nvim/main.h" +#include "nvim/vim.h" +#include "nvim/ui.h" +#include "nvim/memory.h" +#include "nvim/ugrid.h" +#include "nvim/tui/ui_bridge.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "tui/ui_bridge.c.generated.h" +#endif + +#define UI(b) (((UIBridgeData *)b)->ui) + +// Call a function in the UI thread +#define UI_CALL(ui, name, argc, ...) \ + ((UIBridgeData *)ui)->scheduler( \ + event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)) + +#define INT2PTR(i) ((void *)(uintptr_t)i) +#define PTR2INT(p) ((int)(uintptr_t)p) + +UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) +{ + UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData)); + rv->ui = ui; + rv->bridge.rgb = ui->rgb; + rv->bridge.pum_external = ui->pum_external; + rv->bridge.stop = ui_bridge_stop; + rv->bridge.resize = ui_bridge_resize; + rv->bridge.clear = ui_bridge_clear; + rv->bridge.eol_clear = ui_bridge_eol_clear; + rv->bridge.cursor_goto = ui_bridge_cursor_goto; + rv->bridge.update_menu = ui_bridge_update_menu; + rv->bridge.busy_start = ui_bridge_busy_start; + rv->bridge.busy_stop = ui_bridge_busy_stop; + rv->bridge.mouse_on = ui_bridge_mouse_on; + rv->bridge.mouse_off = ui_bridge_mouse_off; + rv->bridge.mode_change = ui_bridge_mode_change; + rv->bridge.set_scroll_region = ui_bridge_set_scroll_region; + rv->bridge.scroll = ui_bridge_scroll; + rv->bridge.highlight_set = ui_bridge_highlight_set; + rv->bridge.put = ui_bridge_put; + rv->bridge.bell = ui_bridge_bell; + rv->bridge.visual_bell = ui_bridge_visual_bell; + rv->bridge.update_fg = ui_bridge_update_fg; + rv->bridge.update_bg = ui_bridge_update_bg; + rv->bridge.update_sp = ui_bridge_update_sp; + rv->bridge.flush = ui_bridge_flush; + rv->bridge.suspend = ui_bridge_suspend; + rv->bridge.set_title = ui_bridge_set_title; + rv->bridge.set_icon = ui_bridge_set_icon; + rv->scheduler = scheduler; + + rv->ui_main = ui_main; + uv_mutex_init(&rv->mutex); + uv_cond_init(&rv->cond); + uv_mutex_lock(&rv->mutex); + rv->ready = false; + + if (uv_thread_create(&rv->ui_thread, ui_thread_run, rv)) { + abort(); + } + + while (!rv->ready) { + uv_cond_wait(&rv->cond, &rv->mutex); + } + uv_mutex_unlock(&rv->mutex); + + ui_attach_impl(&rv->bridge); + return &rv->bridge; +} + +void ui_bridge_stopped(UIBridgeData *bridge) +{ + uv_mutex_lock(&bridge->mutex); + bridge->stopped = true; + uv_mutex_unlock(&bridge->mutex); +} + +static void ui_thread_run(void *data) +{ + UIBridgeData *bridge = data; + bridge->ui_main(bridge, bridge->ui); +} + +static void ui_bridge_stop(UI *b) +{ + UIBridgeData *bridge = (UIBridgeData *)b; + bool stopped = bridge->stopped = false; + UI_CALL(b, stop, 1, b); + for (;;) { + uv_mutex_lock(&bridge->mutex); + stopped = bridge->stopped; + uv_mutex_unlock(&bridge->mutex); + if (stopped) { + break; + } + loop_poll_events(&main_loop, 10); + } + uv_thread_join(&bridge->ui_thread); + uv_mutex_destroy(&bridge->mutex); + uv_cond_destroy(&bridge->cond); + ui_detach_impl(b); + xfree(b); +} +static void ui_bridge_stop_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->stop(ui); +} + +static void ui_bridge_resize(UI *b, int width, int height) +{ + UI_CALL(b, resize, 3, b, INT2PTR(width), INT2PTR(height)); +} +static void ui_bridge_resize_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->resize(ui, PTR2INT(argv[1]), PTR2INT(argv[2])); +} + +static void ui_bridge_clear(UI *b) +{ + UI_CALL(b, clear, 1, b); +} +static void ui_bridge_clear_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->clear(ui); +} + +static void ui_bridge_eol_clear(UI *b) +{ + UI_CALL(b, eol_clear, 1, b); +} +static void ui_bridge_eol_clear_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->eol_clear(ui); +} + +static void ui_bridge_cursor_goto(UI *b, int row, int col) +{ + UI_CALL(b, cursor_goto, 3, b, INT2PTR(row), INT2PTR(col)); +} +static void ui_bridge_cursor_goto_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2])); +} + +static void ui_bridge_update_menu(UI *b) +{ + UI_CALL(b, update_menu, 1, b); +} +static void ui_bridge_update_menu_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->update_menu(ui); +} + +static void ui_bridge_busy_start(UI *b) +{ + UI_CALL(b, busy_start, 1, b); +} +static void ui_bridge_busy_start_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->busy_start(ui); +} + +static void ui_bridge_busy_stop(UI *b) +{ + UI_CALL(b, busy_stop, 1, b); +} +static void ui_bridge_busy_stop_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->busy_stop(ui); +} + +static void ui_bridge_mouse_on(UI *b) +{ + UI_CALL(b, mouse_on, 1, b); +} +static void ui_bridge_mouse_on_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->mouse_on(ui); +} + +static void ui_bridge_mouse_off(UI *b) +{ + UI_CALL(b, mouse_off, 1, b); +} +static void ui_bridge_mouse_off_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->mouse_off(ui); +} + +static void ui_bridge_mode_change(UI *b, int mode) +{ + UI_CALL(b, mode_change, 2, b, INT2PTR(mode)); +} +static void ui_bridge_mode_change_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->mode_change(ui, PTR2INT(argv[1])); +} + +static void ui_bridge_set_scroll_region(UI *b, int top, int bot, int left, + int right) +{ + UI_CALL(b, set_scroll_region, 5, b, INT2PTR(top), INT2PTR(bot), + INT2PTR(left), INT2PTR(right)); +} +static void ui_bridge_set_scroll_region_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->set_scroll_region(ui, PTR2INT(argv[1]), PTR2INT(argv[2]), + PTR2INT(argv[3]), PTR2INT(argv[4])); +} + +static void ui_bridge_scroll(UI *b, int count) +{ + UI_CALL(b, scroll, 2, b, INT2PTR(count)); +} +static void ui_bridge_scroll_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->scroll(ui, PTR2INT(argv[1])); +} + +static void ui_bridge_highlight_set(UI *b, HlAttrs attrs) +{ + HlAttrs *a = xmalloc(sizeof(HlAttrs)); + *a = attrs; + UI_CALL(b, highlight_set, 2, b, a); +} +static void ui_bridge_highlight_set_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->highlight_set(ui, *((HlAttrs *)argv[1])); + xfree(argv[1]); +} + +static void ui_bridge_put(UI *b, uint8_t *text, size_t size) +{ + uint8_t *t = NULL; + if (text) { + t = xmalloc(sizeof(((UCell *)0)->data)); + memcpy(t, text, size); + } + UI_CALL(b, put, 3, b, t, INT2PTR(size)); +} +static void ui_bridge_put_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->put(ui, (uint8_t *)argv[1], (size_t)(uintptr_t)argv[2]); + xfree(argv[1]); +} + +static void ui_bridge_bell(UI *b) +{ + UI_CALL(b, bell, 1, b); +} +static void ui_bridge_bell_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->bell(ui); +} + +static void ui_bridge_visual_bell(UI *b) +{ + UI_CALL(b, visual_bell, 1, b); +} +static void ui_bridge_visual_bell_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->visual_bell(ui); +} + +static void ui_bridge_update_fg(UI *b, int fg) +{ + UI_CALL(b, update_fg, 2, b, INT2PTR(fg)); +} +static void ui_bridge_update_fg_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->update_fg(ui, PTR2INT(argv[1])); +} + +static void ui_bridge_update_bg(UI *b, int bg) +{ + UI_CALL(b, update_bg, 2, b, INT2PTR(bg)); +} +static void ui_bridge_update_bg_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->update_bg(ui, PTR2INT(argv[1])); +} + +static void ui_bridge_update_sp(UI *b, int sp) +{ + UI_CALL(b, update_sp, 2, b, INT2PTR(sp)); +} +static void ui_bridge_update_sp_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->update_sp(ui, PTR2INT(argv[1])); +} + +static void ui_bridge_flush(UI *b) +{ + UI_CALL(b, flush, 1, b); +} +static void ui_bridge_flush_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->flush(ui); +} + +static void ui_bridge_suspend(UI *b) +{ + UIBridgeData *data = (UIBridgeData *)b; + uv_mutex_lock(&data->mutex); + UI_CALL(b, suspend, 1, b); + data->ready = false; + // suspend the main thread until CONTINUE is called by the UI thread + while (!data->ready) { + uv_cond_wait(&data->cond, &data->mutex); + } + uv_mutex_unlock(&data->mutex); +} +static void ui_bridge_suspend_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->suspend(ui); +} + +static void ui_bridge_set_title(UI *b, char *title) +{ + UI_CALL(b, set_title, 2, b, title ? xstrdup(title) : NULL); +} +static void ui_bridge_set_title_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->set_title(ui, argv[1]); + xfree(argv[1]); +} + +static void ui_bridge_set_icon(UI *b, char *icon) +{ + UI_CALL(b, set_icon, 2, b, icon ? xstrdup(icon) : NULL); +} +static void ui_bridge_set_icon_event(void **argv) +{ + UI *ui = UI(argv[0]); + ui->set_icon(ui, argv[1]); + xfree(argv[1]); +} diff --git a/src/nvim/tui/ui_bridge.h b/src/nvim/tui/ui_bridge.h new file mode 100644 index 0000000000..003ed3c2c1 --- /dev/null +++ b/src/nvim/tui/ui_bridge.h @@ -0,0 +1,44 @@ +// Bridge used for communication between a builtin UI thread and nvim core +#ifndef NVIM_TUI_UI_BRIDGE_H +#define NVIM_TUI_UI_BRIDGE_H + +#include + +#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 its 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; + // When a stop request is sent from the main thread, it must wait until the UI + // thread finishes handling all events. This flag is set by the UI thread as a + // signal that it will no longer send messages to the main thread. + bool stopped; +}; + +#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 "tui/ui_bridge.h.generated.h" +#endif +#endif // NVIM_TUI_UI_BRIDGE_H diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c deleted file mode 100644 index 28c7144784..0000000000 --- a/src/nvim/ui_bridge.c +++ /dev/null @@ -1,369 +0,0 @@ -// UI wrapper for the built-in TUI. Sends UI requests to the TUI thread. - -#include -#include -#include -#include - -#include "nvim/main.h" -#include "nvim/vim.h" -#include "nvim/ui.h" -#include "nvim/memory.h" -#include "nvim/ui_bridge.h" -#include "nvim/ugrid.h" - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "ui_bridge.c.generated.h" -#endif - -#define UI(b) (((UIBridgeData *)b)->ui) - -// Call a function in the UI thread -#define UI_CALL(ui, name, argc, ...) \ - ((UIBridgeData *)ui)->scheduler( \ - event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)) - -#define INT2PTR(i) ((void *)(uintptr_t)i) -#define PTR2INT(p) ((int)(uintptr_t)p) - -UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) -{ - UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData)); - rv->ui = ui; - rv->bridge.rgb = ui->rgb; - rv->bridge.pum_external = ui->pum_external; - rv->bridge.stop = ui_bridge_stop; - rv->bridge.resize = ui_bridge_resize; - rv->bridge.clear = ui_bridge_clear; - rv->bridge.eol_clear = ui_bridge_eol_clear; - rv->bridge.cursor_goto = ui_bridge_cursor_goto; - rv->bridge.update_menu = ui_bridge_update_menu; - rv->bridge.busy_start = ui_bridge_busy_start; - rv->bridge.busy_stop = ui_bridge_busy_stop; - rv->bridge.mouse_on = ui_bridge_mouse_on; - rv->bridge.mouse_off = ui_bridge_mouse_off; - rv->bridge.mode_change = ui_bridge_mode_change; - rv->bridge.set_scroll_region = ui_bridge_set_scroll_region; - rv->bridge.scroll = ui_bridge_scroll; - rv->bridge.highlight_set = ui_bridge_highlight_set; - rv->bridge.put = ui_bridge_put; - rv->bridge.bell = ui_bridge_bell; - rv->bridge.visual_bell = ui_bridge_visual_bell; - rv->bridge.update_fg = ui_bridge_update_fg; - rv->bridge.update_bg = ui_bridge_update_bg; - rv->bridge.update_sp = ui_bridge_update_sp; - rv->bridge.flush = ui_bridge_flush; - rv->bridge.suspend = ui_bridge_suspend; - rv->bridge.set_title = ui_bridge_set_title; - rv->bridge.set_icon = ui_bridge_set_icon; - rv->scheduler = scheduler; - - rv->ui_main = ui_main; - uv_mutex_init(&rv->mutex); - uv_cond_init(&rv->cond); - uv_mutex_lock(&rv->mutex); - rv->ready = false; - - if (uv_thread_create(&rv->ui_thread, ui_thread_run, rv)) { - abort(); - } - - while (!rv->ready) { - uv_cond_wait(&rv->cond, &rv->mutex); - } - uv_mutex_unlock(&rv->mutex); - - ui_attach_impl(&rv->bridge); - return &rv->bridge; -} - -void ui_bridge_stopped(UIBridgeData *bridge) -{ - uv_mutex_lock(&bridge->mutex); - bridge->stopped = true; - uv_mutex_unlock(&bridge->mutex); -} - -static void ui_thread_run(void *data) -{ - UIBridgeData *bridge = data; - bridge->ui_main(bridge, bridge->ui); -} - -static void ui_bridge_stop(UI *b) -{ - UIBridgeData *bridge = (UIBridgeData *)b; - bool stopped = bridge->stopped = false; - UI_CALL(b, stop, 1, b); - for (;;) { - uv_mutex_lock(&bridge->mutex); - stopped = bridge->stopped; - uv_mutex_unlock(&bridge->mutex); - if (stopped) { - break; - } - loop_poll_events(&main_loop, 10); - } - uv_thread_join(&bridge->ui_thread); - uv_mutex_destroy(&bridge->mutex); - uv_cond_destroy(&bridge->cond); - ui_detach_impl(b); - xfree(b); -} -static void ui_bridge_stop_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->stop(ui); -} - -static void ui_bridge_resize(UI *b, int width, int height) -{ - UI_CALL(b, resize, 3, b, INT2PTR(width), INT2PTR(height)); -} -static void ui_bridge_resize_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->resize(ui, PTR2INT(argv[1]), PTR2INT(argv[2])); -} - -static void ui_bridge_clear(UI *b) -{ - UI_CALL(b, clear, 1, b); -} -static void ui_bridge_clear_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->clear(ui); -} - -static void ui_bridge_eol_clear(UI *b) -{ - UI_CALL(b, eol_clear, 1, b); -} -static void ui_bridge_eol_clear_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->eol_clear(ui); -} - -static void ui_bridge_cursor_goto(UI *b, int row, int col) -{ - UI_CALL(b, cursor_goto, 3, b, INT2PTR(row), INT2PTR(col)); -} -static void ui_bridge_cursor_goto_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2])); -} - -static void ui_bridge_update_menu(UI *b) -{ - UI_CALL(b, update_menu, 1, b); -} -static void ui_bridge_update_menu_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->update_menu(ui); -} - -static void ui_bridge_busy_start(UI *b) -{ - UI_CALL(b, busy_start, 1, b); -} -static void ui_bridge_busy_start_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->busy_start(ui); -} - -static void ui_bridge_busy_stop(UI *b) -{ - UI_CALL(b, busy_stop, 1, b); -} -static void ui_bridge_busy_stop_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->busy_stop(ui); -} - -static void ui_bridge_mouse_on(UI *b) -{ - UI_CALL(b, mouse_on, 1, b); -} -static void ui_bridge_mouse_on_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->mouse_on(ui); -} - -static void ui_bridge_mouse_off(UI *b) -{ - UI_CALL(b, mouse_off, 1, b); -} -static void ui_bridge_mouse_off_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->mouse_off(ui); -} - -static void ui_bridge_mode_change(UI *b, int mode) -{ - UI_CALL(b, mode_change, 2, b, INT2PTR(mode)); -} -static void ui_bridge_mode_change_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->mode_change(ui, PTR2INT(argv[1])); -} - -static void ui_bridge_set_scroll_region(UI *b, int top, int bot, int left, - int right) -{ - UI_CALL(b, set_scroll_region, 5, b, INT2PTR(top), INT2PTR(bot), - INT2PTR(left), INT2PTR(right)); -} -static void ui_bridge_set_scroll_region_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->set_scroll_region(ui, PTR2INT(argv[1]), PTR2INT(argv[2]), - PTR2INT(argv[3]), PTR2INT(argv[4])); -} - -static void ui_bridge_scroll(UI *b, int count) -{ - UI_CALL(b, scroll, 2, b, INT2PTR(count)); -} -static void ui_bridge_scroll_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->scroll(ui, PTR2INT(argv[1])); -} - -static void ui_bridge_highlight_set(UI *b, HlAttrs attrs) -{ - HlAttrs *a = xmalloc(sizeof(HlAttrs)); - *a = attrs; - UI_CALL(b, highlight_set, 2, b, a); -} -static void ui_bridge_highlight_set_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->highlight_set(ui, *((HlAttrs *)argv[1])); - xfree(argv[1]); -} - -static void ui_bridge_put(UI *b, uint8_t *text, size_t size) -{ - uint8_t *t = NULL; - if (text) { - t = xmalloc(sizeof(((UCell *)0)->data)); - memcpy(t, text, size); - } - UI_CALL(b, put, 3, b, t, INT2PTR(size)); -} -static void ui_bridge_put_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->put(ui, (uint8_t *)argv[1], (size_t)(uintptr_t)argv[2]); - xfree(argv[1]); -} - -static void ui_bridge_bell(UI *b) -{ - UI_CALL(b, bell, 1, b); -} -static void ui_bridge_bell_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->bell(ui); -} - -static void ui_bridge_visual_bell(UI *b) -{ - UI_CALL(b, visual_bell, 1, b); -} -static void ui_bridge_visual_bell_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->visual_bell(ui); -} - -static void ui_bridge_update_fg(UI *b, int fg) -{ - UI_CALL(b, update_fg, 2, b, INT2PTR(fg)); -} -static void ui_bridge_update_fg_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->update_fg(ui, PTR2INT(argv[1])); -} - -static void ui_bridge_update_bg(UI *b, int bg) -{ - UI_CALL(b, update_bg, 2, b, INT2PTR(bg)); -} -static void ui_bridge_update_bg_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->update_bg(ui, PTR2INT(argv[1])); -} - -static void ui_bridge_update_sp(UI *b, int sp) -{ - UI_CALL(b, update_sp, 2, b, INT2PTR(sp)); -} -static void ui_bridge_update_sp_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->update_sp(ui, PTR2INT(argv[1])); -} - -static void ui_bridge_flush(UI *b) -{ - UI_CALL(b, flush, 1, b); -} -static void ui_bridge_flush_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->flush(ui); -} - -static void ui_bridge_suspend(UI *b) -{ - UIBridgeData *data = (UIBridgeData *)b; - uv_mutex_lock(&data->mutex); - UI_CALL(b, suspend, 1, b); - data->ready = false; - // suspend the main thread until CONTINUE is called by the UI thread - while (!data->ready) { - uv_cond_wait(&data->cond, &data->mutex); - } - uv_mutex_unlock(&data->mutex); -} -static void ui_bridge_suspend_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->suspend(ui); -} - -static void ui_bridge_set_title(UI *b, char *title) -{ - UI_CALL(b, set_title, 2, b, title ? xstrdup(title) : NULL); -} -static void ui_bridge_set_title_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->set_title(ui, argv[1]); - xfree(argv[1]); -} - -static void ui_bridge_set_icon(UI *b, char *icon) -{ - UI_CALL(b, set_icon, 2, b, icon ? xstrdup(icon) : NULL); -} -static void ui_bridge_set_icon_event(void **argv) -{ - UI *ui = UI(argv[0]); - ui->set_icon(ui, argv[1]); - xfree(argv[1]); -} diff --git a/src/nvim/ui_bridge.h b/src/nvim/ui_bridge.h deleted file mode 100644 index 45fd0873b4..0000000000 --- a/src/nvim/ui_bridge.h +++ /dev/null @@ -1,44 +0,0 @@ -// Bridge used for communication between a builtin UI thread and nvim core -#ifndef NVIM_UI_BRIDGE_H -#define NVIM_UI_BRIDGE_H - -#include - -#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 its 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; - // When a stop request is sent from the main thread, it must wait until the UI - // thread finishes handling all events. This flag is set by the UI thread as a - // signal that it will no longer send messages to the main thread. - bool stopped; -}; - -#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 -- cgit From 7e6a8310b73579b2fa78fb6c410c7101a9f70254 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 27 Sep 2016 21:46:55 +0200 Subject: log.c: align/adjust layout New: 2016/09/27 18:00:49 INFO 28117/tui_flush:597: ... Old: 2016/09/27 18:00:49 [info @ tui_flush:597] 28117 - ... --- src/nvim/log.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/log.c b/src/nvim/log.c index c31af6b287..bbb4dfb944 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -146,10 +146,10 @@ static bool v_do_log_to_file(FILE *log_file, int log_level, const char* fmt, va_list args) { static const char *log_levels[] = { - [DEBUG_LOG_LEVEL] = "debug", - [INFO_LOG_LEVEL] = "info", - [WARNING_LOG_LEVEL] = "warning", - [ERROR_LOG_LEVEL] = "error" + [DEBUG_LOG_LEVEL] = "DEBUG", + [INFO_LOG_LEVEL] = "INFO ", + [WARNING_LOG_LEVEL] = "WARN ", + [ERROR_LOG_LEVEL] = "ERROR" }; assert(log_level >= DEBUG_LOG_LEVEL && log_level <= ERROR_LOG_LEVEL); @@ -166,8 +166,8 @@ static bool v_do_log_to_file(FILE *log_file, int log_level, // print the log message prefixed by the current timestamp and pid int64_t pid = os_get_pid(); - if (fprintf(log_file, "%s [%s @ %s:%d] %" PRId64 " - ", date_time, - log_levels[log_level], func_name, line_num, pid) < 0) { + if (fprintf(log_file, "%s %s %" PRId64 "/%s:%d: ", date_time, + log_levels[log_level], pid, func_name, line_num) < 0) { return false; } if (vfprintf(log_file, fmt, args) < 0) { -- cgit