diff --git a/modules/libcom/src/osi/os/posix/osdThread.c b/modules/libcom/src/osi/os/posix/osdThread.c index d2c548052..572cff198 100644 --- a/modules/libcom/src/osi/os/posix/osdThread.c +++ b/modules/libcom/src/osi/os/posix/osdThread.c @@ -1024,13 +1024,21 @@ LIBCOM_API void epicsStdCall *epicsThreadPrivateGet(epicsThreadPrivateId id) LIBCOM_API double epicsStdCall epicsThreadSleepQuantum () { -#ifdef CLOCK_REALTIME - struct timespec res; - if (clock_getres(CLOCK_REALTIME, &res) == 0) - return res.tv_sec + 1e-9 * res.tv_nsec; - else + double hz; +#ifndef CLOCK_MONOTONIC_COARSE +#ifdef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC +#else +#define CLOCK_MONOTONIC_COARSE CLOCK_REALTIME #endif - return 1e-3; +#endif + struct timespec res; + if (clock_getres(CLOCK_MONOTONIC_COARSE, &res) == 0) + return res.tv_sec + 1e-9 * res.tv_nsec; + hz = sysconf ( _SC_CLK_TCK ); + if(hz<=0) + return 0.0; + return 1.0 / hz; } LIBCOM_API int epicsThreadGetCPUs(void)