Browse Source
Implement the POSIX_CLOCK_SELECTION Option Group. This was mostly already done, but compiled / linked in the wrong places. E.g. pthread_condattr_getclock() and pthread_condattr_setclock() were in pthread.c and part of POSIX_THREADS_BASE. clock_nanosleep() was in clock.c and part of POSIX_TIMERS. This change builds them as part of clock_selection.c with CONFIG_POSIX_CLOCK_SELECTION. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>pull/89922/head
4 changed files with 77 additions and 32 deletions
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2025 Tenstorrent AI ULC |
||||
# |
||||
# SPDX-License-Identifier: Apache-2.0 |
||||
|
||||
config POSIX_CLOCK_SELECTION |
||||
bool "POSIX Clock Selection" |
||||
help |
||||
Select 'y' here and Zephyr will provide an implementation of the POSIX_CLOCK_SELECTION Option |
||||
Group, which includes the functions clock_nanosleep(), pthread_condattr_getclock(), |
||||
pthread_condattr_setclock(). |
||||
|
||||
For more information, please see |
||||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Meta |
||||
* Copyright (c) 2025 Tenstorrent AI ULC |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
#include "posix_clock.h" |
||||
#include "posix_internal.h" |
||||
|
||||
#include <stddef.h> |
||||
#include <time.h> |
||||
#include <errno.h> |
||||
|
||||
#include <zephyr/posix/time.h> |
||||
#include <zephyr/toolchain.h> |
||||
|
||||
extern int z_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, |
||||
struct timespec *rmtp); |
||||
|
||||
extern int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, |
||||
struct timespec *rmtp) |
||||
{ |
||||
return z_clock_nanosleep(clock_id, flags, rqtp, rmtp); |
||||
} |
||||
|
||||
int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att, |
||||
clockid_t *ZRESTRICT clock_id) |
||||
{ |
||||
struct posix_condattr *const attr = (struct posix_condattr *)att; |
||||
|
||||
if ((attr == NULL) || !attr->initialized) { |
||||
return EINVAL; |
||||
} |
||||
|
||||
*clock_id = attr->clock; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id) |
||||
{ |
||||
struct posix_condattr *const attr = (struct posix_condattr *)att; |
||||
|
||||
if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC) { |
||||
return -EINVAL; |
||||
} |
||||
|
||||
if ((attr == NULL) || !attr->initialized) { |
||||
return EINVAL; |
||||
} |
||||
|
||||
attr->clock = clock_id; |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue