commit e0171b71e792fd30cd6242427faa597cde22e9d7
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Sun Apr 26 18:34:14 2015 +0200

    don't get system time when dealing with null timers
    
    they fire immediately regardless of wall time, so we can save some
    pointless syscalls.

 src/util.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/util.c b/src/util.c
index 6851c6f..8467338 100644
--- a/src/util.c
+++ b/src/util.c
@@ -727,12 +727,12 @@ conf_wakeup( wakeup_t *tmr, int to )
                if (tmr->links.next)
                        list_unlink( &tmr->links );
        } else {
-               time_t timeout = get_now() + to;
-               tmr->timeout = timeout;
+               time_t timeout = to;
                if (!to) {
                        /* We always prepend null timers, to cluster related 
events. */
                        succ = timers.next;
                } else {
+                       timeout += get_now();
                        /* 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). */
                        for (succ = &timers; (head = succ->prev) != &timers; 
succ = head) {
@@ -741,6 +741,7 @@ conf_wakeup( wakeup_t *tmr, int to )
                        }
                        assert( head != &tmr->links );
                }
+               tmr->timeout = timeout;
                if (succ != &tmr->links) {
                        if (tmr->links.next)
                                list_unlink( &tmr->links );
@@ -766,13 +767,13 @@ event_wait( void )
        nowvalid = 0;
        if ((head = timers.next) != &timers) {
                wakeup_t *tmr = (wakeup_t *)head;
-               int delta = tmr->timeout - get_now();
-               if (delta <= 0) {
+               time_t delta = tmr->timeout;
+               if (!delta || (delta -= get_now()) <= 0) {
                        list_unlink( head );
                        tmr->cb( tmr->aux );
                        return;
                }
-               timeout = delta * 1000;
+               timeout = (int)delta * 1000;
        }
        switch (poll( pollfds, npolls, timeout )) {
        case 0:
@@ -803,8 +804,8 @@ event_wait( void )
        nowvalid = 0;
        if ((head = timers.next) != &timers) {
                wakeup_t *tmr = (wakeup_t *)head;
-               int delta = tmr->timeout - get_now();
-               if (delta <= 0) {
+               time_t delta = tmr->timeout;
+               if (!delta || (delta -= get_now()) <= 0) {
                        list_unlink( head );
                        tmr->cb( tmr->aux );
                        return;

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to