summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-29 09:39:47 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-29 09:39:47 +0200
commitee1974debcfba8d8b10ea9a60437d04502b965dc (patch)
tree6d15ce84c937b841363a38bd3f04d2d285d1cf0d /src
parente7aa1ba135d358a0c03c9bcb7157c86a6d9e95c5 (diff)
downloadouroboros-ee1974debcfba8d8b10ea9a60437d04502b965dc.tar.gz
ouroboros-ee1974debcfba8d8b10ea9a60437d04502b965dc.zip
lib: small tweaks for shm_ap_rbuff
Diffstat (limited to 'src')
-rw-r--r--src/lib/shm_ap_rbuff.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 63aa8813..666e053f 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -42,6 +42,7 @@
#define shm_rbuff_used(rb)((*rb->ptr_head + SHM_RBUFF_SIZE - *rb->ptr_tail) \
& (SHM_RBUFF_SIZE - 1))
#define shm_rbuff_free(rb)(shm_rbuff_used(rb) + 1 < SHM_RBUFF_SIZE)
+#define shm_rbuff_empty(rb) (*rb->ptr_head == *rb->ptr_tail)
#define head_el_ptr (rb->shm_base + *rb->ptr_head)
#define tail_el_ptr (rb->shm_base + *rb->ptr_tail)
@@ -239,8 +240,7 @@ int shm_ap_rbuff_write(struct shm_ap_rbuff * rb, struct rb_entry * e)
pthread_mutex_unlock(rb->shm_mutex);
return -1;
}
-
- if (shm_rbuff_used(rb) == 0)
+ if (shm_rbuff_empty(rb))
pthread_cond_broadcast(rb->work);
*head_el_ptr = *e;
@@ -262,11 +262,9 @@ struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
(void*) rb->shm_mutex);
pthread_mutex_lock(rb->shm_mutex);
- while(shm_rbuff_used(rb) == 0)
+ while(shm_rbuff_empty(rb))
pthread_cond_wait(rb->work, rb->shm_mutex);
- pthread_cleanup_pop(0);
-
e = malloc(sizeof(*e));
if (e == NULL) {
pthread_mutex_unlock(rb->shm_mutex);
@@ -277,7 +275,7 @@ struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
*rb->ptr_tail = (*rb->ptr_tail + 1) & (SHM_RBUFF_SIZE -1);
- pthread_mutex_unlock(rb->shm_mutex);
+ pthread_cleanup_pop(1);
return e;
}
@@ -288,7 +286,7 @@ ssize_t shm_ap_rbuff_read_port(struct shm_ap_rbuff * rb, int port_id)
pthread_mutex_lock(rb->shm_mutex);
- if (shm_rbuff_used(rb) == 0) {
+ if (shm_rbuff_empty(rb)) {
pthread_mutex_unlock(rb->shm_mutex);
return -1;
}