mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-02-23 14:09:39 +08:00
Move duplicate timestamp detection into lutil_gettime()
This commit is contained in:
parent
ced581bfa3
commit
6cbf65642a
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user