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 --- src/lib/shm_rbuff_ll.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/lib/shm_rbuff_ll.c') diff --git a/src/lib/shm_rbuff_ll.c b/src/lib/shm_rbuff_ll.c index 4fab0df4..dc7e9f06 100644 --- a/src/lib/shm_rbuff_ll.c +++ b/src/lib/shm_rbuff_ll.c @@ -108,12 +108,7 @@ int shm_rbuff_write_b(struct shm_rbuff * rb, pthread_cleanup_push(__cleanup_mutex_unlock, rb->lock); while (!shm_rbuff_free(rb) && ret != -ETIMEDOUT) { - if (abstime != NULL) - ret = -pthread_cond_timedwait(rb->add, - rb->lock, - abstime); - else - ret = -pthread_cond_wait(rb->add, rb->lock); + ret = -__timedwait(rb->add, rb->lock, abstime); #ifdef HAVE_ROBUST_MUTEX if (ret == -EOWNERDEAD) pthread_mutex_consistent(rb->lock); @@ -187,12 +182,7 @@ ssize_t shm_rbuff_read_b(struct shm_rbuff * rb, pthread_cleanup_push(__cleanup_mutex_unlock, rb->lock); while (shm_rbuff_empty(rb) && (idx != -ETIMEDOUT)) { - if (abstime != NULL) - idx = -pthread_cond_timedwait(rb->add, - rb->lock, - abstime); - else - idx = -pthread_cond_wait(rb->add, rb->lock); + idx = -__timedwait(rb->add, rb->lock, abstime); #ifdef HAVE_ROBUST_MUTEX if (idx == -EOWNERDEAD) pthread_mutex_consistent(rb->lock); -- cgit v1.2.3