From 5ba86d2ec097b7364ebb2d61e9e0d24043d29056 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 30 Mar 2021 20:00:56 -0400 Subject: [PATCH] Fix #844, switch to use CLOCK_REALTIME The portable clock_gettime implementation had been using CLOCK_MONOTONIC to support its use as a PSP timebase for some platforms that used it this way. However with updates on the PSP side this is not required anymore. Preference should be to use CLOCK_REALTIME as it better aligns with the described semantics of the OSAL clock function, and makes for a better default. This can still be easily changed back if the user desires. --- src/os/portable/os-impl-posix-gettime.c | 6 ++++++ src/os/posix/inc/os-impl-gettime.h | 8 +++++++- src/os/rtems/inc/os-impl-gettime.h | 8 +++++++- src/os/vxworks/inc/os-impl-gettime.h | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/os/portable/os-impl-posix-gettime.c b/src/os/portable/os-impl-posix-gettime.c index ddf59232f..0810e0010 100644 --- a/src/os/portable/os-impl-posix-gettime.c +++ b/src/os/portable/os-impl-posix-gettime.c @@ -28,6 +28,12 @@ * The OS-specific code must \#include the correct headers that define the * prototypes for these functions before including this implementation file. * + * NOTE: The OS-specific header must also define which POSIX clock ID to use - + * this specifies the clockid_t parameter to use with clock_gettime(). In + * most cases this should be CLOCK_REALTIME to allow the clock to be set, and + * so the application will also see any manual/administrative clock changes. + * + * The clock ID is selected by defining the #OSAL_GETTIME_SOURCE_CLOCK macro. */ /**************************************************************************************** diff --git a/src/os/posix/inc/os-impl-gettime.h b/src/os/posix/inc/os-impl-gettime.h index c48d6f324..5429be6a0 100644 --- a/src/os/posix/inc/os-impl-gettime.h +++ b/src/os/posix/inc/os-impl-gettime.h @@ -31,6 +31,12 @@ #include "osconfig.h" #include -#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC +/** + * \brief Idenfies the clock ID for OSAL clock operations on POSIX + * + * This is the POSIX clock ID that will be used to implement + * OS_GetLocalTime() and OS_SetLocalTime(). + */ +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_REALTIME #endif /* OS_IMPL_GETTIME_H */ diff --git a/src/os/rtems/inc/os-impl-gettime.h b/src/os/rtems/inc/os-impl-gettime.h index 28690e350..69b8be12a 100644 --- a/src/os/rtems/inc/os-impl-gettime.h +++ b/src/os/rtems/inc/os-impl-gettime.h @@ -31,6 +31,12 @@ #include "osconfig.h" #include -#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC +/** + * \brief Idenfies the clock ID for OSAL clock operations on RTEMS + * + * This is the POSIX clock ID that will be used to implement + * OS_GetLocalTime() and OS_SetLocalTime(). + */ +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_REALTIME #endif /* OS_IMPL_GETTIME_H */ diff --git a/src/os/vxworks/inc/os-impl-gettime.h b/src/os/vxworks/inc/os-impl-gettime.h index 5a66cabd9..fb3354a06 100644 --- a/src/os/vxworks/inc/os-impl-gettime.h +++ b/src/os/vxworks/inc/os-impl-gettime.h @@ -31,6 +31,12 @@ #include "osconfig.h" #include -#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC +/** + * \brief Idenfies the clock ID for OSAL clock operations on VxWorks + * + * This is the POSIX clock ID that will be used to implement + * OS_GetLocalTime() and OS_SetLocalTime(). + */ +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_REALTIME #endif /* OS_IMPL_GETTIME_H */