posix: clock: implement clock_getres()
clock_getres() is required by the POSIX_TIMERS Option Group as detailed in Section E.1 of IEEE-1003.1-2017. The POSIX_TIMERS Option Group is required for PSE51, PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory for any POSIX conforming system as per Section A.2.1.3 of IEEE-1003-1.2017. With this, we have complete support for the POSIX_TIMERS Option Group. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
parent
06f6c5c992
commit
d36dd8097e
|
@ -87,6 +87,7 @@ static inline int32_t _ts_to_ms(const struct timespec *to)
|
|||
}
|
||||
|
||||
int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
||||
int clock_getres(clockid_t clock_id, struct timespec *ts);
|
||||
int clock_settime(clockid_t clock_id, const struct timespec *ts);
|
||||
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
|
||||
/* Timer APIs */
|
||||
|
|
|
@ -97,6 +97,28 @@ int clock_gettime(clockid_t clock_id, struct timespec *ts)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int clock_getres(clockid_t clock_id, struct timespec *res)
|
||||
{
|
||||
BUILD_ASSERT(CONFIG_SYS_CLOCK_TICKS_PER_SEC > 0 &&
|
||||
CONFIG_SYS_CLOCK_TICKS_PER_SEC <= NSEC_PER_SEC,
|
||||
"CONFIG_SYS_CLOCK_TICKS_PER_SEC must be > 0 and <= NSEC_PER_SEC");
|
||||
|
||||
if (!(clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_REALTIME ||
|
||||
clock_id == CLOCK_PROCESS_CPUTIME_ID)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (res != NULL) {
|
||||
*res = (struct timespec){
|
||||
.tv_sec = 0,
|
||||
.tv_nsec = NSEC_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC,
|
||||
};
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the time of the specified clock.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue