Skip to content

Commit 396fc20

Browse files
authored
posix: Ensure CLOCK_REALTIME and CLOCK_MONOTONIC use Zephyr clock IDs
Some toolchains may define CLOCK_REALTIME and CLOCK_MONOTONIC in their libc headers with values that differ from Zephyr's internal SYS_CLOCK_REALTIME and SYS_CLOCK_MONOTONIC. To ensure consistent behavior across all boards and toolchains, undefine these macros and redefine them to match Zephyr's expected clock IDs. This prevents mismatched clock IDs being passed to the kernel, avoiding invalid clockid errors when using functions like clock_gettime(). Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
1 parent 322da1d commit 396fc20

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

include/zephyr/posix/time.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ struct itimerspec {
6666
extern "C" {
6767
#endif
6868

69-
#ifndef CLOCK_REALTIME
69+
#undef CLOCK_REALTIME
7070
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
71-
#endif
7271

7372
#ifndef CLOCK_PROCESS_CPUTIME_ID
7473
#define CLOCK_PROCESS_CPUTIME_ID 2
@@ -78,13 +77,11 @@ extern "C" {
7877
#define CLOCK_THREAD_CPUTIME_ID 3
7978
#endif
8079

81-
#ifndef CLOCK_MONOTONIC
80+
#undef CLOCK_MONOTONIC
8281
#define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC
83-
#endif
8482

85-
#ifndef TIMER_ABSTIME
83+
#undef TIMER_ABSTIME
8684
#define TIMER_ABSTIME SYS_TIMER_ABSTIME
87-
#endif
8885

8986
int clock_gettime(clockid_t clock_id, struct timespec *ts);
9087
int clock_getres(clockid_t clock_id, struct timespec *ts);

0 commit comments

Comments
 (0)