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 {
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;
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;
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;
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
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