-
- /* Milisecond resolution (actually, best case is about 10 ms resolution) */
- return 1000 * GetTickCount();
+ else
+ {
+ /* Fallback on GetTickCount() which has a milisecond resolution
+ * (actually, best case is about 10 ms resolution)
+ * GetTickCount() only returns a DWORD thus will wrap after
+ * about 49.7 days so we try to detect the wrapping. */
+
+ static CRITICAL_SECTION date_lock;
+ static mtime_t i_previous_time = I64C(-1);
+ static int i_wrap_counts = -1;
+
+ if( i_wrap_counts == -1 )
+ {
+ /* Initialization */
+ i_previous_time = usec_time;
+ InitializeCriticalSection( &date_lock );
+ i_wrap_counts = 0;
+ }
+
+ EnterCriticalSection( &date_lock );
+ usec_time = I64C(1000) *
+ (i_wrap_counts * I64C(0x100000000) + GetTickCount());
+ if( i_previous_time > usec_time )
+ {
+ /* Counter wrapped */
+ i_wrap_counts++;
+ usec_time += I64C(0x100000000000);
+ }
+ i_previous_time = usec_time;
+ LeaveCriticalSection( &date_lock );
+
+ return usec_time;
+ }