diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2023-10-07 14:26:23 +0200 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2023-10-25 09:53:27 +0200 |
commit | 5706bf3efa8d8262982bbed15fb041e536f56cf2 (patch) | |
tree | 3cd9db132bb5756bdaa64982b63ad9b9dbe4aaad /include | |
parent | 180e92c5f13b99ed171e8efe11058eb943bc6506 (diff) | |
download | ouroboros-5706bf3efa8d8262982bbed15fb041e536f56cf2.tar.gz ouroboros-5706bf3efa8d8262982bbed15fb041e536f56cf2.zip |
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 <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'include')
-rw-r--r-- | include/ouroboros/pthread.h | 10 |
1 files changed, 10 insertions, 0 deletions
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 <pthread.h> +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) { |