os: Add GetTimeInMicros
64-bit higher resolution current time value. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
parent
0c33f47281
commit
2d96948ab5
|
@ -165,6 +165,7 @@ extern void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
|
|||
#endif
|
||||
|
||||
extern _X_EXPORT CARD32 GetTimeInMillis(void);
|
||||
extern _X_EXPORT CARD64 GetTimeInMicros(void);
|
||||
|
||||
extern _X_EXPORT void AdjustWaitForDelay(pointer /*waitTime */ ,
|
||||
unsigned long /*newdelay */ );
|
||||
|
|
27
os/utils.c
27
os/utils.c
|
@ -430,6 +430,11 @@ GetTimeInMillis(void)
|
|||
{
|
||||
return GetTickCount();
|
||||
}
|
||||
CARD64
|
||||
GetTimeInMicros(void)
|
||||
{
|
||||
return (CARD64) GetTickCount() * 1000;
|
||||
}
|
||||
#else
|
||||
CARD32
|
||||
GetTimeInMillis(void)
|
||||
|
@ -460,6 +465,28 @@ GetTimeInMillis(void)
|
|||
X_GETTIMEOFDAY(&tv);
|
||||
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
CARD64
|
||||
GetTimeInMicros(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
#ifdef MONOTONIC_CLOCK
|
||||
struct timespec tp;
|
||||
static clockid_t clockid;
|
||||
|
||||
if (!clockid) {
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
|
||||
clockid = CLOCK_MONOTONIC;
|
||||
else
|
||||
clockid = ~0L;
|
||||
}
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
|
||||
return (CARD64) tp.tv_sec * (CARD64)1000000 + tp.tv_nsec / 1000;
|
||||
#endif
|
||||
|
||||
X_GETTIMEOFDAY(&tv);
|
||||
return (CARD64) tv.tv_sec * (CARD64)1000000000 + (CARD64) tv.tv_usec * 1000;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue
Block a user