Browse Source

posix: implement the POSIX_CLOCK_SELECTION Option Group

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
Chris Friedt 3 months ago committed by Anas Nashif
parent
commit
ae4a1dbf2c
  1. 8
      lib/posix/options/CMakeLists.txt
  2. 13
      lib/posix/options/Kconfig.clock_selection
  3. 56
      lib/posix/options/clock_selection.c
  4. 32
      lib/posix/options/cond.c

8
lib/posix/options/CMakeLists.txt

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
zephyr_syscall_header_ifdef(CONFIG_POSIX_CLOCK_SELECTION posix_clock.h)
zephyr_syscall_header_ifdef(CONFIG_POSIX_TIMERS posix_clock.h)
zephyr_syscall_header_ifdef(CONFIG_XSI_SINGLE_PROCESS posix_clock.h)
@ -45,6 +46,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS) @@ -45,6 +46,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS)
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
endif()
if (NOT CONFIG_TC_PROVIDES_POSIX_CLOCK_SELECTION)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK_SELECTION
clock_common.c
clock_selection.c
)
endif()
if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
fnmatch.c

13
lib/posix/options/Kconfig.clock_selection

@ -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

56
lib/posix/options/clock_selection.c

@ -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;
}

32
lib/posix/options/cond.c

@ -276,36 +276,4 @@ int pthread_condattr_destroy(pthread_condattr_t *att) @@ -276,36 +276,4 @@ int pthread_condattr_destroy(pthread_condattr_t *att)
return 0;
}
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) {
LOG_DBG("%s %s initialized", "attribute", "not");
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) {
LOG_DBG("%s %s initialized", "attribute", "not");
return EINVAL;
}
attr->clock = clock_id;
return 0;
}
SYS_INIT(pthread_cond_pool_init, PRE_KERNEL_1, 0);

Loading…
Cancel
Save