mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
event: Remove "priority" concept.
It was replaced by the "child queue" concept (MultiQueue).
This commit is contained in:
@@ -6,23 +6,16 @@
|
|||||||
|
|
||||||
#define EVENT_HANDLER_MAX_ARGC 6
|
#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 void (*argv_callback)(void **argv);
|
||||||
typedef struct message {
|
typedef struct message {
|
||||||
int priority;
|
|
||||||
argv_callback handler;
|
argv_callback handler;
|
||||||
void *argv[EVENT_HANDLER_MAX_ARGC];
|
void *argv[EVENT_HANDLER_MAX_ARGC];
|
||||||
} Event;
|
} Event;
|
||||||
typedef void(*event_scheduler)(Event event, void *data);
|
typedef void(*event_scheduler)(Event event, void *data);
|
||||||
|
|
||||||
#define VA_EVENT_INIT(event, p, h, a) \
|
#define VA_EVENT_INIT(event, h, a) \
|
||||||
do { \
|
do { \
|
||||||
assert(a <= EVENT_HANDLER_MAX_ARGC); \
|
assert(a <= EVENT_HANDLER_MAX_ARGC); \
|
||||||
(event)->priority = p; \
|
|
||||||
(event)->handler = h; \
|
(event)->handler = h; \
|
||||||
if (a) { \
|
if (a) { \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
@@ -34,11 +27,11 @@ typedef void(*event_scheduler)(Event event, void *data);
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} 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);
|
assert(argc <= EVENT_HANDLER_MAX_ARGC);
|
||||||
Event event;
|
Event event;
|
||||||
VA_EVENT_INIT(&event, priority, cb, argc);
|
VA_EVENT_INIT(&event, cb, argc);
|
||||||
return event;
|
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.
|
/// Removes all events without processing them.
|
||||||
void multiqueue_purge_events(MultiQueue *this)
|
void multiqueue_purge_events(MultiQueue *this)
|
||||||
{
|
{
|
||||||
|
@@ -10,7 +10,7 @@ typedef struct multiqueue MultiQueue;
|
|||||||
typedef void (*put_callback)(MultiQueue *multiq, void *data);
|
typedef void (*put_callback)(MultiQueue *multiq, void *data);
|
||||||
|
|
||||||
#define multiqueue_put(q, h, ...) \
|
#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
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
|
@@ -604,7 +604,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(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;
|
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(1, wait_input_enqueue, 1, input));
|
loop_schedule(&main_loop, event_create(wait_input_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);
|
||||||
@@ -352,7 +352,7 @@ static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
|
|||||||
stream_close(&input->read_stream, NULL, NULL);
|
stream_close(&input->read_stream, NULL, NULL);
|
||||||
multiqueue_put(input->loop->fast_events, restart_reading, 1, input);
|
multiqueue_put(input->loop->fast_events, restart_reading, 1, input);
|
||||||
} else {
|
} else {
|
||||||
loop_schedule(&main_loop, event_create(1, input_done_event, 0));
|
loop_schedule(&main_loop, event_create(input_done_event, 0));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -773,7 +773,7 @@ static void tui_suspend(UI *ui)
|
|||||||
// before continuing. This is done in another callback to avoid
|
// before continuing. This is done in another callback to avoid
|
||||||
// loop_poll_events recursion
|
// loop_poll_events recursion
|
||||||
multiqueue_put_event(data->loop->fast_events,
|
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)
|
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)
|
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)
|
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; \
|
uilog_event = ui_bridge_##name##_event; \
|
||||||
} \
|
} \
|
||||||
((UIBridgeData *)ui)->scheduler( \
|
((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)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
// Schedule a function call on the UI bridge thread.
|
// Schedule a function call on the UI bridge thread.
|
||||||
#define UI_CALL(ui, name, argc, ...) \
|
#define UI_CALL(ui, name, argc, ...) \
|
||||||
((UIBridgeData *)ui)->scheduler( \
|
((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
|
#endif
|
||||||
|
|
||||||
#define INT2PTR(i) ((void *)(uintptr_t)i)
|
#define INT2PTR(i) ((void *)(uintptr_t)i)
|
||||||
|
Reference in New Issue
Block a user