From 5706bf3efa8d8262982bbed15fb041e536f56cf2 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 7 Oct 2023 14:26:23 +0200 Subject: lib: Wrap pthread_cond_timedwait for NULL abstime We often have the pattern where we NULL-check abstime for pthread_cond_timedwait to call pthread_cond_wait if it is. Added a __timedwait function to wrap this. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- include/ouroboros/pthread.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/ouroboros') diff --git a/include/ouroboros/pthread.h b/include/ouroboros/pthread.h index 917c078b..05821dd1 100644 --- a/include/ouroboros/pthread.h +++ b/include/ouroboros/pthread.h @@ -25,6 +25,16 @@ #include +static int __attribute__((unused)) __timedwait(pthread_cond_t * cond, + pthread_mutex_t * mtx, + const struct timespec * abstime) +{ + if (abstime == NULL) + return pthread_cond_wait(cond, mtx); + + return pthread_cond_timedwait(cond, mtx, abstime); +} + /* various cleanup functions for pthread_cleanup_push */ static void __attribute__((unused)) __cleanup_rwlock_unlock(void * rwlock) { -- cgit v1.2.3