diff --git a/src/liblwevent/200_eventloop.c b/src/liblwevent/200_eventloop.c index 2931303..aeaecc6 100644 --- a/src/liblwevent/200_eventloop.c +++ b/src/liblwevent/200_eventloop.c @@ -90,7 +90,7 @@ void lwevent_exit(void) int lwevent_loop(void) { while(!lwevent_loop_exit) { - if(lwevent_wait(-1) == -1) { + if(lwevent_wait(-1, 0) == -1) { if(errno == EINTR) continue; return -1; } @@ -125,7 +125,7 @@ static void _lwevent_invalid(struct lwevent* ev) * Wrapper around epoll_wait(2). For every returned event, we assume the object has an associated * struct lwevent in the struct epoll_event. */ -int lwevent_wait(int timeout_ms) +int lwevent_wait(int timeout_ms, void (*before_loop)(void)) { int ret, i, revents; struct lwevent* ev; @@ -137,6 +137,8 @@ int lwevent_wait(int timeout_ms) ret = epoll_wait(lwevent_epoll_fd, _lw_revents, _lw_revents_size, timeout_ms); if(ret == -1) return -1; + if(before_loop) before_loop(); + /* process returned events */ for(i = 0; i < ret; ++i) { ev = (struct lwevent*)(_lw_revents[i].data.ptr); diff --git a/src/liblwevent/200_eventloop.h b/src/liblwevent/200_eventloop.h index 32c8741..95b8029 100644 --- a/src/liblwevent/200_eventloop.h +++ b/src/liblwevent/200_eventloop.h @@ -61,7 +61,7 @@ extern volatile int lwevent_loop_exit; \retval -1 on error (system call failed; see \a errno). This function will call lwevent_wait() in a loop forever. The loop can be aborted by setting the -flag lwevent_loop_exit to non-zero. The loop will also be aborted if lwevent_wait() returns an +flag \ref lwevent_loop_exit to non-zero. The loop will also be aborted if lwevent_wait() returns an error (in which case \a errno can be used to determine the error). */ @@ -73,6 +73,8 @@ int lwevent_loop(void); \param timeout_ms A timeout, in milliseconds. This function will return as soon as any events occur, but will return after \a timeout_ms milliseconds have elapsed. +\param before_loop If specified, a function which is called after \c epoll_wait(2) but before + processing events. May be 0. \returns Number of events processed. \retval 0 on timeout. \retval -1 on error (system call failed; see \a errno). @@ -85,12 +87,16 @@ objects that are closed during the callbacks. \a timeout_ms may be specified as a negative number to disable timeouts and wait forever, or as 0 to return immediately even if no events are available. A positive number is a duration in milliseconds. +\a before_loop may be used to run a function before looping over any returned events. Some programs +may wish to record the time at the top of the event loop, for example, to avoid polling for it +multiple times while processing events. + \note If a signal is received while in \c epoll_wait(2), this function will return -1 and \a errno will be set to \c EINTR. This is not a permanent error condition. lwevent_loop() will catch this condition and continue to loop. */ -int lwevent_wait(int timeout_ms); +int lwevent_wait(int timeout_ms, void (*before_loop)(void)); diff --git a/src/liblwevent/soversion b/src/liblwevent/soversion index 7af9988..fc6bc49 100644 --- a/src/liblwevent/soversion +++ b/src/liblwevent/soversion @@ -9,7 +9,7 @@ # SOMAJOR is included in the library's soname, and needs to be bumped # after a binary-incompatible release. It is a single integer. -SOMAJOR=0 +SOMAJOR=1 # SOMICRO is bumped every time there is a binary-compatible release. SOMICRO=0 diff --git a/version b/version index 3d4b62f..623f2ef 100644 --- a/version +++ b/version @@ -11,7 +11,7 @@ # expected to be in 'major.minor.micro' format. VERMAJOR=1 VERMINOR=0 -VERMICRO=0 +VERMICRO=1 # kate: replace-trailing-space-save true; space-indent true; tab-width 4; # vim: expandtab:ts=4:sw=4:syntax=sh