]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] introduce now_ms, the current date in milliseconds
authorWilly Tarreau <w@1wt.eu>
Sun, 29 Jun 2008 11:47:25 +0000 (13:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 29 Jun 2008 11:47:25 +0000 (13:47 +0200)
This new time value will be used to compute timeouts and wait queue
positions. The operation is made once for all when time is retrieved.
A future improvement might consist in having it in ticks of 1/1024
second and to convert all timeouts into ticks.

include/common/time.h
src/time.c

index 82ec402ccd7f379d29d9572a9e87f0f348ecdc38..7dbed6d732d11bc4669382a3e516c9d859d1020c 100644 (file)
@@ -54,6 +54,7 @@
 #define MINTIME(old, new)      (((new)<0)?(old):(((old)<0||(new)<(old))?(new):(old)))
 #define SETNOW(a)              (*a=now)
 
+extern unsigned int   now_ms;           /* internal date in milliseconds (may wrap) */
 extern struct timeval now;              /* internal date is a monotonic function of real clock */
 extern struct timeval date;             /* the real current date */
 extern struct timeval start_date;       /* the process's start date */
index f637f6c78a9eb2756d236c1dccbe70196809ae7f..5318dcdf2665608ab14ea78fc7eb24faf57cad53 100644 (file)
@@ -16,6 +16,7 @@
 #include <common/standard.h>
 #include <common/time.h>
 
+unsigned int   now_ms;          /* internal date in milliseconds (may wrap) */
 struct timeval now;             /* internal date is a monotonic function of real clock */
 struct timeval date;            /* the real current date */
 struct timeval start_date;      /* the process's start date */
@@ -162,7 +163,7 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted)
        if (unlikely(max_wait < 0)) {
                tv_zero(&tv_offset);
                now = date;
-               return;
+               goto to_ms;
        }
        __tv_add(&adjusted, &date, &tv_offset);
        if (unlikely(__tv_islt(&adjusted, &now))) {
@@ -178,7 +179,7 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted)
                goto fixup; /* jump in the future */
        }
        now = adjusted;
-       return;
+       goto to_ms;
  fixup:
        /* Large jump. If the poll was interrupted, we consider that the date
         * has not changed (immediate wake-up), otherwise we add the poll
@@ -192,6 +193,8 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted)
                tv_offset.tv_usec += 1000000;
                tv_offset.tv_sec--;
        }
+ to_ms:
+       now_ms = now.tv_sec * 1000 + now.tv_usec / 1000;
        return;
 }