#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <xev.h>
#define UNUSED(v) ((void)v);
xev_cb_action timer_callback(xev_loop* loop, xev_completion* c, int result, void *userdata) {
UNUSED(loop); UNUSED(c); UNUSED(result);
xev_async_notify((xev_watcher *)userdata);
return XEV_DISARM;
}
xev_cb_action async_callback(xev_loop* loop, xev_completion* c, int result, void *userdata) {
UNUSED(loop); UNUSED(c); UNUSED(result);
bool *notified = (bool *)userdata;
*notified = true;
return XEV_DISARM;
}
int main(void) {
xev_loop loop;
if (xev_loop_init(&loop) != 0) {
printf("xev_loop_init failure\n");
return 1;
}
xev_completion async_c;
xev_watcher async;
if (xev_async_init(&async) != 0) {
printf("xev_async_init failure\n");
return 1;
}
bool notified = false;
xev_async_wait(&async, &loop, &async_c, ¬ified, &async_callback);
xev_completion timer_c;
xev_watcher timer;
if (xev_timer_init(&timer) != 0) {
printf("xev_timer_init failure\n");
return 1;
}
xev_timer_run(&timer, &loop, &timer_c, 1, &async, &timer_callback);
xev_loop_run(&loop, XEV_RUN_UNTIL_DONE);
if (!notified) {
printf("FAIL! async should've been notified!");
return 1;
}
xev_timer_deinit(&timer);
xev_async_deinit(&async);
xev_loop_deinit(&loop);
return 0;
}