event: Remove "priority" concept.

It was replaced by the "child queue" concept (MultiQueue).
This commit is contained in:
Justin M. Keyes 2017-04-27 14:38:41 +02:00
parent f17a818519
commit 8f59d14839
8 changed files with 11 additions and 45 deletions

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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

View File

@ -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));
}
/*

View File

@ -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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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)