diff options
author | Sander Vrijders <[email protected]> | 2016-05-17 20:17:09 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-05-17 21:33:48 +0200 |
commit | 81e32e5d19bdc0dabd7473a31ddb0d6f1c95e18e (patch) | |
tree | 1f926effe772c1ef49a1fb2109e13171a4a14e28 | |
parent | 950bc6a4c195e8751ada64c7c9a3f842adbc23c5 (diff) | |
download | ouroboros-81e32e5d19bdc0dabd7473a31ddb0d6f1c95e18e.tar.gz ouroboros-81e32e5d19bdc0dabd7473a31ddb0d6f1c95e18e.zip |
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.
-rw-r--r-- | src/lib/shm_du_map.c | 7 |
1 files 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); |