summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-14 16:39:27 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-14 21:34:04 +0200
commit037fec33cda726d0078e23798f462ad273153dd5 (patch)
tree25c9ef679a0aaa93e5f01f2a68512d8eaf76f3e7 /src/lib
parentc56a4ed3b865b4b240c6f01809c935b7b86d160b (diff)
downloadouroboros-037fec33cda726d0078e23798f462ad273153dd5.tar.gz
ouroboros-037fec33cda726d0078e23798f462ad273153dd5.zip
ipcpd: shim-udp: complete locking
Added necessary locks for the shim-udp. This PR also improves thread management, the main thread now starts a mainloop thread, which spawns sdu handler threads when it the IPCP is enrolled. If the IPCP exits the enrolled state, the sdu loop is cancelled.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/shm_ap_rbuff.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 6c977cbb..6c04ccc5 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -245,18 +245,17 @@ struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
if (rb == NULL)
return NULL;
- e = malloc(sizeof(*e));
- if (e == NULL)
- return NULL;
-
pthread_mutex_lock(rb->shm_mutex);
if (shm_rbuff_used(rb) == 0) {
pthread_mutex_unlock(rb->shm_mutex);
- free(e);
return NULL;
}
+ e = malloc(sizeof(*e));
+ if (e == NULL)
+ return NULL;
+
*e = *(rb->shm_base + *rb->ptr_tail);
*rb->ptr_tail = (*rb->ptr_tail + 1) & (SHM_RBUFF_SIZE -1);