Always use CLOCK_MONOTONIC if it's available on Unix
This commit is contained in:
@@ -125,21 +125,18 @@ static void TestTLS()
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
clockid_t g_Clock = CLOCK_REALTIME;
|
clockid_t g_Clock = CLOCK_REALTIME;
|
||||||
|
|
||||||
void OpenGetTime()
|
void OpenGetTime()
|
||||||
{
|
{
|
||||||
static bool bInitialized = false;
|
static bool bInitialized = false;
|
||||||
|
|
||||||
if( bInitialized )
|
if( bInitialized )
|
||||||
return;
|
return;
|
||||||
bInitialized = true;
|
bInitialized = true;
|
||||||
|
|
||||||
/* Check whether the clock is actually supported. */
|
/* Check whether CLOCK_MONOTONIC is supported.
|
||||||
|
* If it isn't available, use CLOCK_REALTIME.*/
|
||||||
timespec ts;
|
timespec ts;
|
||||||
if( clock_getres(CLOCK_MONOTONIC, &ts) == -1 )
|
if( clock_gettime(CLOCK_MONOTONIC, &ts) == -1 )
|
||||||
return;
|
|
||||||
|
|
||||||
/* If the resolution is worse than a millisecond, fall back on CLOCK_REALTIME. */
|
|
||||||
if( ts.tv_sec > 0 || ts.tv_nsec > 1000000 )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_Clock = CLOCK_MONOTONIC;
|
g_Clock = CLOCK_MONOTONIC;
|
||||||
|
|||||||
Reference in New Issue
Block a user