From 6e6eb242188e8312a6a8a78e6be0d11cd1036610 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 18 Mar 2026 21:17:10 +0000 Subject: MacOS doesn't have pthread_mutex_timedlock -_- --- src/libposixplz/pthread_mutex_tailock.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/libposixplz/pthread_mutex_tailock.c (limited to 'src/libposixplz/pthread_mutex_tailock.c') diff --git a/src/libposixplz/pthread_mutex_tailock.c b/src/libposixplz/pthread_mutex_tailock.c new file mode 100644 index 0000000..736921c --- /dev/null +++ b/src/libposixplz/pthread_mutex_tailock.c @@ -0,0 +1,41 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include + +#ifdef SKALIBS_HASPTHREADMUTEXTIMEDLOCK + +int pthread_mutex_tailock (pthread_mutex_t *mtx, tain const *deadline, tain *stamp) +{ + int e ; + struct timespec ts ; + tain tto ; + if (!stamp) return pthread_mutex_lock(mtx) ; + tain_sub(&tto, deadline, stamp) ; + if (!timespec_from_tain_relative(&ts, &tto)) return errno ; +#ifdef SKALIBS_HASPTHREADMUTEXCLOCKLOCK + if (&tain_now != &tain_wallclock_read) + e = pthread_mutex_clocklock(mtx, CLOCK_MONOTONIC, &ts) ; + else +#else + e = pthread_mutex_timedlock(mtx, &ts) ; +#endif + tain_now(stamp) ; + return e ; +} + +#else + +int pthread_mutex_tailock (pthread_mutex_t *mtx, tain const *deadline, tain *stamp) +{ + (void)deadline ; + (void)stamp ; + return pthread_mutex_lock(mtx) ; +} + +#endif -- cgit v1.3.1