Skip to content

Commit 247ce21

Browse files
committed
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>
1 parent 9dd7e32 commit 247ce21

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

lib/posix/options/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
44

5+
zephyr_syscall_header_ifdef(CONFIG_POSIX_CLOCK_SELECTION posix_clock.h)
56
zephyr_syscall_header_ifdef(CONFIG_POSIX_TIMERS posix_clock.h)
67
zephyr_syscall_header_ifdef(CONFIG_XSI_SINGLE_PROCESS posix_clock.h)
78

@@ -45,6 +46,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS)
4546
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
4647
endif()
4748

49+
if (NOT CONFIG_TC_PROVIDES_POSIX_CLOCK_SELECTION)
50+
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK_SELECTION
51+
clock_common.c
52+
clock_selection.c
53+
)
54+
endif()
55+
4856
if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
4957
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
5058
fnmatch.c
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Tenstorrent AI ULC
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config POSIX_CLOCK_SELECTION
6+
bool "POSIX Clock Selection"
7+
help
8+
Select 'y' here and Zephyr will provide an implementation of the POSIX_CLOCK_SELECTION Option
9+
Group, which includes the functions clock_nanosleep(), pthread_condattr_getclock(),
10+
pthread_condattr_setclock().
11+
12+
For more information, please see
13+
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

lib/posix/options/cond.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -287,36 +287,4 @@ int pthread_condattr_destroy(pthread_condattr_t *att)
287287
return 0;
288288
}
289289

290-
int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att,
291-
clockid_t *ZRESTRICT clock_id)
292-
{
293-
struct posix_condattr *const attr = (struct posix_condattr *)att;
294-
295-
if ((attr == NULL) || !attr->initialized) {
296-
LOG_DBG("condattr is not initialized");
297-
return EINVAL;
298-
}
299-
300-
*clock_id = attr->clock;
301-
302-
return 0;
303-
}
304-
305-
int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id)
306-
{
307-
struct posix_condattr *const attr = (struct posix_condattr *)att;
308-
309-
if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC) {
310-
return -EINVAL;
311-
}
312-
313-
if ((attr == NULL) || !attr->initialized) {
314-
LOG_DBG("condattr is not initialized");
315-
return EINVAL;
316-
}
317-
318-
attr->clock = clock_id;
319-
320-
return 0;
321-
}
322290
SYS_INIT(pthread_cond_pool_init, PRE_KERNEL_1, 0);

0 commit comments

Comments
 (0)