return -1;
}
-/* return a broken out time, with microseconds */
+/* return a broken out time, with microseconds
+ * Must be mutex-protected.
+ */
#ifdef _WIN32
/* Windows SYSTEMTIME only has 10 millisecond resolution, so we
* also need to use a high resolution timer to get microseconds.
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