mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
uev_run() with only UEV_NONBLOCK never returns when there are watchers
but no events, it spins at full CPU load:
uev_run(ctx, UEV_NONBLOCK);
The loop polls epoll with a zero timeout and only stops on UEV_ONCE.
Leave the loop when a nonblocking poll finds no events.
36 lines
616 B
C
36 lines
616 B
C
/* Verifies that UEV_NONBLOCK returns when no event is pending */
|
|
#include "check.h"
|
|
|
|
static int fired;
|
|
|
|
static void cb(uev_t *w, void *arg, int events)
|
|
{
|
|
fired++;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
uev_ctx_t ctx;
|
|
uev_t w;
|
|
|
|
fail_unless(uev_init(&ctx) == 0);
|
|
fail_unless(uev_event_init(&ctx, &w, cb, NULL) == 0);
|
|
|
|
alarm(2);
|
|
fail_unless(uev_run(&ctx, UEV_NONBLOCK) == 0);
|
|
fail_unless(fired == 0);
|
|
|
|
fail_unless(uev_event_post(&w) == 0);
|
|
fail_unless(uev_run(&ctx, UEV_NONBLOCK) == 0);
|
|
fail_unless(fired == 1);
|
|
|
|
return uev_exit(&ctx);
|
|
}
|
|
|
|
/**
|
|
* Local Variables:
|
|
* indent-tabs-mode: t
|
|
* c-file-style: "linux"
|
|
* End:
|
|
*/
|