From 7d2494b7f978f715f53a4e6bb4ed024a600c1f15 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 17 Jul 2018 21:10:14 +0200 Subject: [PATCH] Fix bug of SPMC / MPMC snapshots: not all items in buffers were properly cleared. --- m-snapshot.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/m-snapshot.h b/m-snapshot.h index 66c7b5d3..e0cd6ddf 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -338,6 +338,12 @@ static inline unsigned int snapshot_mrsw_int_get_write_idx(snapshot_mrsw_int_t s return s->currentWrite; } +static inline unsigned int snapshot_mrsw_int_size(snapshot_mrsw_int_t s) +{ + SNAPSHOTI_SPMC_INT_CONTRACT(s); + return s->n - SNAPSHOTI_SPMC_EXTRA_BUFFER; +} + static inline unsigned int snapshot_mrsw_int_write_idx(snapshot_mrsw_int_t s, unsigned int idx) { SNAPSHOTI_SPMC_INT_CONTRACT(s); @@ -511,7 +517,8 @@ static inline void snapshot_mrsw_int_read_end(snapshot_mrsw_int_t s, unsigned in static inline void M_C(name, _clear)(M_C(name, _t) snap) \ { \ SNAPSHOTI_SPMC_CONTRACT(snap); \ - for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \ + size_t nReader = snapshot_mrsw_int_size(snap->core); \ + for(size_t i = 0; i < nReader + SNAPSHOTI_SPMC_EXTRA_BUFFER; i++) { \ M_GET_CLEAR oplist(snap->data[i].x); \ } \ M_GET_FREE oplist (snap->data); \