]> git.sur5r.net Git - openldap/commitdiff
Move duplicate timestamp detection into lutil_gettime()
authorHoward Chu <hyc@openldap.org>
Sun, 11 Feb 2007 13:42:29 +0000 (13:42 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 11 Feb 2007 13:42:29 +0000 (13:42 +0000)
include/lutil.h
libraries/liblutil/csn.c
libraries/liblutil/utils.c

index c5b9c528cf4f51bdd90472b8027c10541df3f3cd..49ea7951938dbc163b0e516b1b3b9d6d7ae0fc5d 100644 (file)
@@ -158,6 +158,7 @@ typedef struct lutil_tm {
        int tm_mon;     /* month 0-11 */
        int tm_year;    /* year - 1900 */
        int tm_usec;    /* microseconds */
+       int tm_usub;    /* submicro */
 } lutil_tm;
 
 typedef struct lutil_timet {
index bab1dd9a8bd1261e7a1ad7f9ccbdfa6fd5421d82..4c3213f741880da44bff783ec5b87a538efe26f6 100644 (file)
@@ -52,29 +52,14 @@ size_t
 lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
 {
        struct lutil_tm tm;
-       static unsigned int csnop;
-       static int prev_sec, prev_usec;
-
-       unsigned int op;
        int n;
 
        lutil_gettime( &tm );
 
-       if ( tm.tm_sec > prev_sec || ( tm.tm_sec == prev_sec &&
-               tm.tm_usec > prev_usec )) {
-               prev_sec = tm.tm_sec;
-               prev_usec = tm.tm_usec;
-               csnop = 0;
-       } else {
-               tm.tm_sec = prev_sec;
-               tm.tm_usec = prev_usec;
-       }
-       op = csnop++;
-
        n = snprintf( buf, len,
                "%4d%02d%02d%02d%02d%02d.%06dZ#%06x#%03x#%06x",
            tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
-           tm.tm_min, tm.tm_sec, tm.tm_usec, op, replica, mod );
+           tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_usub, replica, mod );
 
        if( n < 0 ) return 0;
        return ( (size_t) n < len ) ? n : 0;
index 3f34a319fea208beea6c99e2b861f83fcf8fdc94..3891cfacf17060273cb8c8821da5a21705ac273b 100644 (file)
@@ -282,6 +282,8 @@ void
 lutil_gettime( struct lutil_tm *tm )
 {
        static LARGE_INTEGER cFreq;
+       static LARGE_INTEGER prevCount;
+       static int subs;
        static int offset;
        LARGE_INTEGER count;
        SYSTEMTIME st;
@@ -306,6 +308,18 @@ lutil_gettime( struct lutil_tm *tm )
                offset = ( usec - st.wMilliseconds ) * 1000;
        }
 
+       /* It shouldn't ever go backwards, but multiple CPUs might
+        * be able to hit in the same tick.
+        */
+       if ( count.QuadPart <= prevCount.QuadPart ) {
+               subs++;
+       } else {
+               subs = 0;
+               prevCount = count;
+       }
+
+       tm->tm_usub = subs;
+
        /* convert to microseconds */
        count.QuadPart *= 1000000;
        count.QuadPart /= cFreq.QuadPart;
@@ -329,6 +343,9 @@ void
 lutil_gettime( struct lutil_tm *ltm )
 {
        struct timeval tv;
+       static struct timeval prevTv;
+       static int subs;
+
 #ifdef HAVE_GMTIME_R
        struct tm tm_buf;
 #endif
@@ -338,6 +355,16 @@ lutil_gettime( struct lutil_tm *ltm )
        gettimeofday( &tv, NULL );
        t = tv.tv_sec;
 
+       if ( tv.tv_sec < prevTv.tv_sec
+               || ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec == prevTv.tv_usec )) {
+               subs++;
+       } else {
+               subs = 0;
+               prevTv = tv;
+       }
+
+       ltm->tm_usub = subs;
+
 #ifdef HAVE_GMTIME_R
        tm = gmtime_r( &t, &tm_buf );
 #else