From 037fec33cda726d0078e23798f462ad273153dd5 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 14 May 2016 16:39:27 +0200 Subject: 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. --- src/lib/shm_ap_rbuff.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/lib/shm_ap_rbuff.c') 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); -- cgit v1.2.3