From 81e32e5d19bdc0dabd7473a31ddb0d6f1c95e18e Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 17 May 2016 20:17:09 +0200 Subject: lib: Fixed incorrect initialization When moving the tail pointer in the DU map, blocks was never reset to zero. This caused it to sometimes clean up too many DUs. --- src/lib/shm_du_map.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index a7ec5ac9..1bd89744 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -294,7 +294,8 @@ ssize_t shm_create_du_buff(struct shm_du_map * dum, --blocks; } - index = (*dum->ptr_head - 1) & (SHM_BLOCKS_IN_MAP - 1); + index = (*dum->ptr_head - 1 + SHM_BLOCKS_IN_MAP) + & (SHM_BLOCKS_IN_MAP - 1); pthread_mutex_unlock(dum->shm_mutex); @@ -353,14 +354,14 @@ int shm_release_du_buff(struct shm_du_map * dum, ssize_t idx) while (get_tail_ptr(dum)->garbage == 1) { sz = get_tail_ptr(dum)->size; - - while (sz + (long) sizeof (struct shm_du_buff) > 0) { + while (sz + (long) sizeof(struct shm_du_buff) > 0) { sz -= SHM_DU_BUFF_BLOCK_SIZE; ++blocks; } *(dum->ptr_tail) = (*dum->ptr_tail + blocks) & (SHM_BLOCKS_IN_MAP - 1); + blocks = 0; } pthread_mutex_unlock(dum->shm_mutex); -- cgit v1.2.3