diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index b1a0d52995b..2f6350d5b10 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -19,6 +19,7 @@ config POSIX_API config PTHREAD_IPC bool "POSIX pthread IPC API" default y if POSIX_API + depends on POSIX_CLOCK help This enables a mostly-standards-compliant implementation of the pthread mutex, condition variable and barrier IPC diff --git a/lib/posix/semaphore.c b/lib/posix/semaphore.c index 26a36f5c93a..3d60ddec8dd 100644 --- a/lib/posix/semaphore.c +++ b/lib/posix/semaphore.c @@ -91,6 +91,7 @@ int sem_post(sem_t *semaphore) int sem_timedwait(sem_t *semaphore, struct timespec *abstime) { int32_t timeout; + struct timespec current; int64_t current_ms, abstime_ms; __ASSERT(abstime, "abstime pointer NULL"); @@ -100,8 +101,12 @@ int sem_timedwait(sem_t *semaphore, struct timespec *abstime) return -1; } - current_ms = (int64_t)k_uptime_get(); + if (clock_gettime(CLOCK_REALTIME, ¤t) < 0) { + return -1; + } + abstime_ms = (int64_t)_ts_to_ms(abstime); + current_ms = (int64_t)_ts_to_ms(¤t); if (abstime_ms <= current_ms) { timeout = 0; diff --git a/samples/net/sockets/socketpair/prj.conf b/samples/net/sockets/socketpair/prj.conf index b884d633797..4f5d22d808b 100644 --- a/samples/net/sockets/socketpair/prj.conf +++ b/samples/net/sockets/socketpair/prj.conf @@ -12,4 +12,5 @@ CONFIG_TEST_RANDOM_GENERATOR=y # Use Portable threads CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_CLOCK=y CONFIG_NET_SOCKETS_POSIX_NAMES=y