don't get system time when dealing with null timers

they fire immediately regardless of wall time, so we can save some
pointless syscalls.
This commit is contained in:
Oswald Buddenhagen 2015-04-26 18:34:14 +02:00
parent 59ac6b3f20
commit e0171b71e7

View File

@ -727,12 +727,12 @@ conf_wakeup( wakeup_t *tmr, int to )
if (tmr->links.next) if (tmr->links.next)
list_unlink( &tmr->links ); list_unlink( &tmr->links );
} else { } else {
time_t timeout = get_now() + to; time_t timeout = to;
tmr->timeout = timeout;
if (!to) { if (!to) {
/* We always prepend null timers, to cluster related events. */ /* We always prepend null timers, to cluster related events. */
succ = timers.next; succ = timers.next;
} else { } else {
timeout += get_now();
/* We start at the end in the expectation that the newest timer is likely to fire last /* We start at the end in the expectation that the newest timer is likely to fire last
* (which will be true only if all timeouts are equal, but it's an as good guess as any). */ * (which will be true only if all timeouts are equal, but it's an as good guess as any). */
for (succ = &timers; (head = succ->prev) != &timers; succ = head) { for (succ = &timers; (head = succ->prev) != &timers; succ = head) {
@ -741,6 +741,7 @@ conf_wakeup( wakeup_t *tmr, int to )
} }
assert( head != &tmr->links ); assert( head != &tmr->links );
} }
tmr->timeout = timeout;
if (succ != &tmr->links) { if (succ != &tmr->links) {
if (tmr->links.next) if (tmr->links.next)
list_unlink( &tmr->links ); list_unlink( &tmr->links );
@ -766,13 +767,13 @@ event_wait( void )
nowvalid = 0; nowvalid = 0;
if ((head = timers.next) != &timers) { if ((head = timers.next) != &timers) {
wakeup_t *tmr = (wakeup_t *)head; wakeup_t *tmr = (wakeup_t *)head;
int delta = tmr->timeout - get_now(); time_t delta = tmr->timeout;
if (delta <= 0) { if (!delta || (delta -= get_now()) <= 0) {
list_unlink( head ); list_unlink( head );
tmr->cb( tmr->aux ); tmr->cb( tmr->aux );
return; return;
} }
timeout = delta * 1000; timeout = (int)delta * 1000;
} }
switch (poll( pollfds, npolls, timeout )) { switch (poll( pollfds, npolls, timeout )) {
case 0: case 0:
@ -803,8 +804,8 @@ event_wait( void )
nowvalid = 0; nowvalid = 0;
if ((head = timers.next) != &timers) { if ((head = timers.next) != &timers) {
wakeup_t *tmr = (wakeup_t *)head; wakeup_t *tmr = (wakeup_t *)head;
int delta = tmr->timeout - get_now(); time_t delta = tmr->timeout;
if (delta <= 0) { if (!delta || (delta -= get_now()) <= 0) {
list_unlink( head ); list_unlink( head );
tmr->cb( tmr->aux ); tmr->cb( tmr->aux );
return; return;