summaryrefslogtreecommitdiff
path: root/src/lib/shm_ap_rbuff.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-08 10:29:06 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-08 10:29:06 +0200
commitc1e1831ded0330771fd175f1c8138ed82c90f9f8 (patch)
tree617e3002ffa5addb364c01d5cd925d8c609b12b5 /src/lib/shm_ap_rbuff.c
parentd5b71449bc18116444720257ba640e3c597ff6e9 (diff)
parent8450af0e2950e5a1415e38702d6169cc8a732294 (diff)
downloadouroboros-c1e1831ded0330771fd175f1c8138ed82c90f9f8.tar.gz
ouroboros-c1e1831ded0330771fd175f1c8138ed82c90f9f8.zip
Merged in dstaesse/ouroboros/be-bugfixing (pull request #187)
bugfixes
Diffstat (limited to 'src/lib/shm_ap_rbuff.c')
-rw-r--r--src/lib/shm_ap_rbuff.c16
1 files changed, 1 insertions, 15 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 56555533..e9c51533 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -52,9 +52,6 @@
#define shm_rbuff_empty(rb) (*rb->ptr_head == *rb->ptr_tail)
#define head_el_ptr(rb) (rb->shm_base + *rb->ptr_head)
#define tail_el_ptr(rb) (rb->shm_base + *rb->ptr_tail)
-#define clean_sdus(rb) \
- while (!shm_rbuff_empty(rb) && tail_el_ptr(rb)->port_id < 0) \
- *rb->ptr_tail = (*rb->ptr_tail + 1) & (SHM_BUFFER_SIZE -1); \
struct shm_ap_rbuff {
struct rb_entry * shm_base; /* start of entry */
@@ -173,6 +170,7 @@ struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t api)
shm_fd = shm_open(fn, O_RDWR, 0666);
if (shm_fd == -1) {
LOG_DBG("%d failed opening shared memory %s.", getpid(), fn);
+ free(rb);
return NULL;
}
@@ -315,8 +313,6 @@ int shm_ap_rbuff_peek(struct shm_ap_rbuff * rb,
pthread_mutex_consistent(rb->lock);
}
- clean_sdus(rb);
-
while (shm_rbuff_empty(rb)) {
if (timeout != NULL)
ret = pthread_cond_timedwait(rb->add,
@@ -325,8 +321,6 @@ int shm_ap_rbuff_peek(struct shm_ap_rbuff * rb,
else
ret = pthread_cond_wait(rb->add, rb->lock);
- clean_sdus(rb);
-
if (ret == EOWNERDEAD) {
LOG_DBG("Recovering dead mutex.");
pthread_mutex_consistent(rb->lock);
@@ -360,8 +354,6 @@ struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
pthread_mutex_consistent(rb->lock);
}
- clean_sdus(rb);
-
while (shm_rbuff_empty(rb))
if (pthread_cond_wait(rb->add, rb->lock) == EOWNERDEAD) {
LOG_DBG("Recovering dead mutex.");
@@ -392,8 +384,6 @@ ssize_t shm_ap_rbuff_read_port(struct shm_ap_rbuff * rb, int port_id)
pthread_mutex_consistent(rb->lock);
}
- clean_sdus(rb);
-
if (shm_rbuff_empty(rb) || tail_el_ptr(rb)->port_id != port_id) {
pthread_mutex_unlock(rb->lock);
return -1;
@@ -428,8 +418,6 @@ ssize_t shm_ap_rbuff_read_port_b(struct shm_ap_rbuff * rb,
ts_add(&abstime, timeout, &abstime);
}
- clean_sdus(rb);
-
pthread_cleanup_push((void(*)(void *))pthread_mutex_unlock,
(void *) rb->lock);
@@ -441,8 +429,6 @@ ssize_t shm_ap_rbuff_read_port_b(struct shm_ap_rbuff * rb,
else
ret = pthread_cond_wait(rb->del, rb->lock);
- clean_sdus(rb);
-
if (ret == EOWNERDEAD) {
LOG_DBG("Recovering dead mutex.");
pthread_mutex_consistent(rb->lock);