summaryrefslogtreecommitdiff
path: root/src/lib/shm_rdrbuff.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-07-12 12:16:34 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-07-12 12:17:58 +0200
commiteaa2dff945366ed43b28fb1ae8e5c10ce95d9964 (patch)
treec2e257101d4f52190a5fc6e2e00e8b6d8d637932 /src/lib/shm_rdrbuff.c
parent9f553e440bd540ac46c98fa13ddf93e81daff221 (diff)
downloadouroboros-eaa2dff945366ed43b28fb1ae8e5c10ce95d9964.tar.gz
ouroboros-eaa2dff945366ed43b28fb1ae8e5c10ce95d9964.zip
irmd: Shutdown sanitizer without cancellation
Diffstat (limited to 'src/lib/shm_rdrbuff.c')
-rw-r--r--src/lib/shm_rdrbuff.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index ed9c3847..1f999f93 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -264,8 +264,15 @@ struct shm_rdrbuff * shm_rdrbuff_open()
return rdrb;
}
-void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb)
+int shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb,
+ struct timespec * timeo)
{
+ struct timespec abstime;
+
+ if (timeo != NULL) {
+ clock_gettime(PTHREAD_COND_CLOCK, &abstime);
+ ts_add(&abstime, timeo, &abstime);
+ }
#ifdef __APPLE__
pthread_mutex_lock(rdrb->lock);
@@ -273,21 +280,33 @@ void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb)
if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD)
pthread_mutex_consistent(rdrb->lock);
#endif
- pthread_cleanup_push((void (*)(void *)) pthread_mutex_unlock,
- (void *) rdrb->lock);
while (shm_rdrb_free(rdrb, WAIT_BLOCKS)) {
#ifdef __APPLE__
- pthread_cond_wait(rdrb->full, rdrb->lock);
+ if (pthread_cond_timedwait(rdrb->full,
+ rdrb->lock
+ &abstime) == ETIMEDOUT) {
+ pthread_mutex_unlock(rdrb->lock);
+ return -ETIMEDOUT;
+ }
#else
- if (pthread_cond_wait(rdrb->full, rdrb->lock) == EOWNERDEAD)
+ int ret = pthread_cond_timedwait(rdrb->full,
+ rdrb->lock,
+ &abstime);
+ if (ret == EOWNERDEAD)
pthread_mutex_consistent(rdrb->lock);
+ if (ret == ETIMEDOUT) {
+ pthread_mutex_unlock(rdrb->lock);
+ return -ETIMEDOUT;
+ }
#endif
}
garbage_collect(rdrb);
- pthread_cleanup_pop(true);
+ pthread_mutex_unlock(rdrb->lock);
+
+ return 0;
}
void shm_rdrbuff_close(struct shm_rdrbuff * rdrb)