aboutsummaryrefslogtreecommitdiffstats
path: root/src/libposixplz
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-03-18 21:17:10 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-03-18 21:17:10 +0000
commit6e6eb242188e8312a6a8a78e6be0d11cd1036610 (patch)
tree02cb09a553f32bb5fbb671528ab900a1636c7bce /src/libposixplz
parentebce1a511a60f3b4a9785c3962eaa381206c914f (diff)
downloadskalibs-6e6eb242188e8312a6a8a78e6be0d11cd1036610.tar.gz
MacOS doesn't have pthread_mutex_timedlock -_-
Diffstat (limited to 'src/libposixplz')
-rw-r--r--src/libposixplz/pthread_mutex_tailock.c41
1 files changed, 41 insertions, 0 deletions
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 <errno.h>
+#include <time.h>
+#include <pthread.h>
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/tai.h>
+#include <skalibs/pthread.h>
+
+#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