events: loop_schedule() is unclear, rename it loop_schedule_fast()

This commit is contained in:
Björn Linse
2019-08-29 12:48:01 +02:00
parent 7a85792884
commit f8b5d6e124
5 changed files with 15 additions and 11 deletions

View File

@@ -71,7 +71,7 @@ bool loop_poll_events(Loop *loop, int ms)
return timeout_expired; return timeout_expired;
} }
/// Schedules an event from another thread. /// Schedules a fast event from another thread.
/// ///
/// @note Event is queued into `fast_events`, which is processed outside of the /// @note Event is queued into `fast_events`, which is processed outside of the
/// primary `events` queue by loop_poll_events(). For `main_loop`, that /// primary `events` queue by loop_poll_events(). For `main_loop`, that
@@ -79,7 +79,7 @@ bool loop_poll_events(Loop *loop, int ms)
/// (VimState.execute), so redraw and other side-effects are likely to be /// (VimState.execute), so redraw and other side-effects are likely to be
/// skipped. /// skipped.
/// @see loop_schedule_deferred /// @see loop_schedule_deferred
void loop_schedule(Loop *loop, Event event) void loop_schedule_fast(Loop *loop, Event event)
{ {
uv_mutex_lock(&loop->mutex); uv_mutex_lock(&loop->mutex);
multiqueue_put_event(loop->thread_events, event); multiqueue_put_event(loop->thread_events, event);
@@ -87,15 +87,15 @@ void loop_schedule(Loop *loop, Event event)
uv_mutex_unlock(&loop->mutex); uv_mutex_unlock(&loop->mutex);
} }
/// Schedules an event from another thread. Unlike loop_schedule(), the event /// Schedules an event from another thread. Unlike loop_schedule_fast(), the
/// is forwarded to `Loop.events`, instead of being processed immediately. /// event is forwarded to `Loop.events`, instead of being processed immediately.
/// ///
/// @see loop_schedule /// @see loop_schedule_fast
void loop_schedule_deferred(Loop *loop, Event event) void loop_schedule_deferred(Loop *loop, Event event)
{ {
Event *eventp = xmalloc(sizeof(*eventp)); Event *eventp = xmalloc(sizeof(*eventp));
*eventp = event; *eventp = event;
loop_schedule(loop, event_create(loop_deferred_event, 2, loop, eventp)); loop_schedule_fast(loop, event_create(loop_deferred_event, 2, loop, eventp));
} }
static void loop_deferred_event(void **argv) static void loop_deferred_event(void **argv)
{ {

View File

@@ -753,7 +753,7 @@ void msg_schedule_emsgf(const char *const fmt, ...)
va_end(ap); va_end(ap);
char *s = xstrdup((char *)IObuff); char *s = xstrdup((char *)IObuff);
loop_schedule(&main_loop, event_create(msg_emsgf_event, 1, s)); multiqueue_put(main_loop.events, msg_emsgf_event, 1, s);
} }
/* /*

View File

@@ -164,7 +164,7 @@ static void tinput_flush(TermInput *input, bool wait_until_empty)
size_t drain_boundary = wait_until_empty ? 0 : 0xff; size_t drain_boundary = wait_until_empty ? 0 : 0xff;
do { do {
uv_mutex_lock(&input->key_buffer_mutex); uv_mutex_lock(&input->key_buffer_mutex);
loop_schedule(&main_loop, event_create(tinput_wait_enqueue, 1, input)); loop_schedule_fast(&main_loop, event_create(tinput_wait_enqueue, 1, input));
input->waiting = true; input->waiting = true;
while (input->waiting) { while (input->waiting) {
uv_cond_wait(&input->key_buffer_cond, &input->key_buffer_mutex); uv_cond_wait(&input->key_buffer_cond, &input->key_buffer_mutex);
@@ -522,7 +522,7 @@ static void tinput_read_cb(Stream *stream, RBuffer *buf, size_t count_,
TermInput *input = data; TermInput *input = data;
if (eof) { if (eof) {
loop_schedule(&main_loop, event_create(tinput_done_event, 0)); loop_schedule_fast(&main_loop, event_create(tinput_done_event, 0));
return; return;
} }

View File

@@ -454,7 +454,7 @@ static void tui_scheduler(Event event, void *d)
{ {
UI *ui = d; UI *ui = d;
TUIData *data = ui->data; TUIData *data = ui->data;
loop_schedule(data->loop, event); // `tui_loop` local to tui_main(). loop_schedule_fast(data->loop, event); // `tui_loop` local to tui_main().
} }
#ifdef UNIX #ifdef UNIX

View File

@@ -228,7 +228,11 @@ static void ui_refresh_event(void **argv)
void ui_schedule_refresh(void) void ui_schedule_refresh(void)
{ {
loop_schedule(&main_loop, event_create(ui_refresh_event, 0)); // TODO(bfredl): "fast" is not optimal. UI should be refreshed only at
// deferred processing plus a few more blocked-on-input situtions like
// wait_return(), but not any os_breakcheck(). Alternatively make this
// defered and make wait_return() process deferred events already.
loop_schedule_fast(&main_loop, event_create(ui_refresh_event, 0));
} }
void ui_default_colors_set(void) void ui_default_colors_set(void)