Compare commits

..

4 Commits

Author SHA1 Message Date
Laurence Withers 21b1983fd7 Bump version 2007-11-15 12:07:04 +00:00
Laurence Withers e1594acd7c Bump version 2007-11-15 12:07:04 +00:00
Laurence Withers 20c828b73c Add `before_loop' parameter to lwevent_wait() 2007-11-15 12:06:55 +00:00
Laurence Withers b1b20b641c Add explicit reference to variable in documentation 2007-11-15 11:59:16 +00:00
4 changed files with 14 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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