mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
event: Remove "priority" concept.
It was replaced by the "child queue" concept (MultiQueue).
This commit is contained in:
parent
f17a818519
commit
8f59d14839
@ -6,23 +6,16 @@
|
||||
|
||||
#define EVENT_HANDLER_MAX_ARGC 6
|
||||
|
||||
typedef enum {
|
||||
kEvPriorityNormal = 1,
|
||||
kEvPriorityAsync = 2, // safe to run in any state
|
||||
} EventPriority;
|
||||
|
||||
typedef void (*argv_callback)(void **argv);
|
||||
typedef struct message {
|
||||
int priority;
|
||||
argv_callback handler;
|
||||
void *argv[EVENT_HANDLER_MAX_ARGC];
|
||||
} Event;
|
||||
typedef void(*event_scheduler)(Event event, void *data);
|
||||
|
||||
#define VA_EVENT_INIT(event, p, h, a) \
|
||||
#define VA_EVENT_INIT(event, h, a) \
|
||||
do { \
|
||||
assert(a <= EVENT_HANDLER_MAX_ARGC); \
|
||||
(event)->priority = p; \
|
||||
(event)->handler = h; \
|
||||
if (a) { \
|
||||
va_list args; \
|
||||
@ -34,11 +27,11 @@ typedef void(*event_scheduler)(Event event, void *data);
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline Event event_create(int priority, argv_callback cb, int argc, ...)
|
||||
static inline Event event_create(argv_callback cb, int argc, ...)
|
||||
{
|
||||
assert(argc <= EVENT_HANDLER_MAX_ARGC);
|
||||
Event event;
|
||||
VA_EVENT_INIT(&event, priority, cb, argc);
|
||||
VA_EVENT_INIT(&event, cb, argc);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
@ -152,33 +152,6 @@ void multiqueue_process_events(MultiQueue *this)
|
||||
}
|
||||
}
|
||||
|
||||
void multiqueue_process_priority(MultiQueue *this, int priority)
|
||||
{
|
||||
assert(this);
|
||||
QUEUE *start = QUEUE_HEAD(&this->headtail);
|
||||
QUEUE *cur = start;
|
||||
while (!multiqueue_empty(this)) {
|
||||
MultiQueueItem *item = multiqueue_node_data(cur);
|
||||
assert(!item->link || !this->parent); // Only a parent queue has link-nodes
|
||||
Event ev = multiqueueitem_get_event(item, false);
|
||||
|
||||
if (ev.priority >= priority) {
|
||||
if (ev.handler) {
|
||||
ev.handler(ev.argv);
|
||||
}
|
||||
// Processed. Remove this item and get the new head.
|
||||
(void)multiqueue_remove(this);
|
||||
cur = QUEUE_HEAD(&this->headtail);
|
||||
} else {
|
||||
// Not processed. Skip this item and get the next one.
|
||||
cur = cur->next->next;
|
||||
if (!cur || cur == start) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes all events without processing them.
|
||||
void multiqueue_purge_events(MultiQueue *this)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ typedef struct multiqueue MultiQueue;
|
||||
typedef void (*put_callback)(MultiQueue *multiq, void *data);
|
||||
|
||||
#define multiqueue_put(q, h, ...) \
|
||||
multiqueue_put_event(q, event_create(kEvPriorityNormal, h, __VA_ARGS__));
|
||||
multiqueue_put_event(q, event_create(h, __VA_ARGS__));
|
||||
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
@ -604,7 +604,7 @@ void msg_schedule_emsgf(const char *const fmt, ...)
|
||||
va_end(ap);
|
||||
|
||||
char *s = xstrdup((char *)IObuff);
|
||||
loop_schedule(&main_loop, event_create(1, msg_emsgf_event, 1, s));
|
||||
loop_schedule(&main_loop, event_create(msg_emsgf_event, 1, s));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -102,7 +102,7 @@ static void flush_input(TermInput *input, bool wait_until_empty)
|
||||
size_t drain_boundary = wait_until_empty ? 0 : 0xff;
|
||||
do {
|
||||
uv_mutex_lock(&input->key_buffer_mutex);
|
||||
loop_schedule(&main_loop, event_create(1, wait_input_enqueue, 1, input));
|
||||
loop_schedule(&main_loop, event_create(wait_input_enqueue, 1, input));
|
||||
input->waiting = true;
|
||||
while (input->waiting) {
|
||||
uv_cond_wait(&input->key_buffer_cond, &input->key_buffer_mutex);
|
||||
@ -352,7 +352,7 @@ static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
|
||||
stream_close(&input->read_stream, NULL, NULL);
|
||||
multiqueue_put(input->loop->fast_events, restart_reading, 1, input);
|
||||
} else {
|
||||
loop_schedule(&main_loop, event_create(1, input_done_event, 0));
|
||||
loop_schedule(&main_loop, event_create(input_done_event, 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ static void tui_suspend(UI *ui)
|
||||
// before continuing. This is done in another callback to avoid
|
||||
// loop_poll_events recursion
|
||||
multiqueue_put_event(data->loop->fast_events,
|
||||
event_create(1, suspend_event, 1, ui));
|
||||
event_create(suspend_event, 1, ui));
|
||||
}
|
||||
|
||||
static void tui_set_title(UI *ui, char *title)
|
||||
|
@ -198,7 +198,7 @@ static void ui_refresh_event(void **argv)
|
||||
|
||||
void ui_schedule_refresh(void)
|
||||
{
|
||||
loop_schedule(&main_loop, event_create(1, ui_refresh_event, 0));
|
||||
loop_schedule(&main_loop, event_create(ui_refresh_event, 0));
|
||||
}
|
||||
|
||||
void ui_resize(int new_width, int new_height)
|
||||
|
@ -40,13 +40,13 @@ static argv_callback uilog_event = NULL;
|
||||
uilog_event = ui_bridge_##name##_event; \
|
||||
} \
|
||||
((UIBridgeData *)ui)->scheduler( \
|
||||
event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)); \
|
||||
event_create(ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)); \
|
||||
} while (0)
|
||||
#else
|
||||
// Schedule a function call on the UI bridge thread.
|
||||
#define UI_CALL(ui, name, argc, ...) \
|
||||
((UIBridgeData *)ui)->scheduler( \
|
||||
event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
|
||||
event_create(ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
|
||||
#endif
|
||||
|
||||
#define INT2PTR(i) ((void *)(uintptr_t)i)
|
||||
|
Loading…
Reference in New Issue
Block a user