diff options
author | Sander Vrijders <[email protected]> | 2018-10-09 17:18:06 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2018-10-09 17:18:06 +0200 |
commit | 2806b069f6dd95588e31c4357548bd44a6940607 (patch) | |
tree | c03bec5777762d00b8b1d502201e5be8aedbba86 /src | |
parent | 1d4501adf6da8f55dea85c0389b911b24e722620 (diff) | |
parent | ee1e7fe6c4d101569d045bcc8b99d7f0779f7e96 (diff) | |
download | ouroboros-2806b069f6dd95588e31c4357548bd44a6940607.tar.gz ouroboros-2806b069f6dd95588e31c4357548bd44a6940607.zip |
Merge branch 'testing' into be
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/shm_rdrbuff.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 31d9f2b6..e9ef9222 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -81,7 +81,6 @@ struct shm_rdrbuff { size_t * head; /* start of ringbuffer head */ size_t * tail; /* start of ringbuffer tail */ pthread_mutex_t * lock; /* lock all free space in shm */ - pthread_cond_t * full; /* flag when full */ pthread_cond_t * healthy; /* flag when packet is read */ pid_t * pid; /* pid of the irmd owner */ }; @@ -184,8 +183,7 @@ static struct shm_rdrbuff * rdrb_create(int flags) rdrb->head = (size_t *) ((uint8_t *) rdrb->shm_base + SHM_BLOCKS_SIZE); rdrb->tail = rdrb->head + 1; rdrb->lock = (pthread_mutex_t *) (rdrb->tail + 1); - rdrb->full = (pthread_cond_t *) (rdrb->lock + 1); - rdrb->healthy = rdrb->full + 1; + rdrb->healthy = (pthread_cond_t *) (rdrb->lock + 1); rdrb->pid = (pid_t *) (rdrb->healthy + 1); free(shm_rdrb_fn); @@ -237,9 +235,6 @@ struct shm_rdrbuff * shm_rdrbuff_create() #ifndef __APPLE__ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); #endif - if (pthread_cond_init(rdrb->full, &cattr)) - goto fail_full; - if (pthread_cond_init(rdrb->healthy, &cattr)) goto fail_healthy; @@ -254,8 +249,6 @@ struct shm_rdrbuff * shm_rdrbuff_create() return rdrb; fail_healthy: - pthread_cond_destroy(rdrb->full); - fail_full: pthread_condattr_destroy(&cattr); fail_cattr: pthread_mutex_destroy(rdrb->lock); @@ -323,7 +316,6 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, #else if (!shm_rdrb_free(rdrb, 1)) { #endif - pthread_cond_broadcast(rdrb->full); pthread_mutex_unlock(rdrb->lock); return -EAGAIN; } @@ -375,7 +367,6 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, #ifdef SHM_RDRB_MULTI_BLOCK size_t blocks = 0; size_t padblocks = 0; - size_t rblocks; #endif ssize_t sz = size + sizeof(*sdb); int ret = 0; @@ -390,7 +381,6 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, sz -= SHM_RDRB_BLOCK_SIZE; ++blocks; } - rblocks = blocks; #endif #ifndef HAVE_ROBUST_MUTEX pthread_mutex_lock(rdrb->lock); @@ -402,14 +392,13 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, (void *) rdrb->lock); #ifdef SHM_RDRB_MULTI_BLOCK - if (blocks > 1) - rblocks = blocks << 1; + if (blocks + *rdrb->head > (SHM_BUFFER_SIZE)) + padblocks = (SHM_BUFFER_SIZE) - *rdrb->head; - while (!shm_rdrb_free(rdrb, rblocks) && ret != ETIMEDOUT) { + while (!shm_rdrb_free(rdrb, blocks + padblocks) && ret != ETIMEDOUT) { #else while (!shm_rdrb_free(rdrb, 1) && ret != ETIMEDOUT) { #endif - pthread_cond_broadcast(rdrb->full); if (abstime != NULL) ret = pthread_cond_timedwait(rdrb->healthy, rdrb->lock, |