From 64f67d036be90a229dd4fef796113339a418e086 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 24 Feb 2023 16:18:54 +0100 Subject: [PATCH] fix epicsThreadSleepQuantum not to fail epicsTimeTest because of unrealistically high clock resolution --- modules/libcom/src/osi/os/posix/osdThread.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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)