Hello Gabor Dozsa,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/c/public/gem5/+/17188
to review the following change.
Change subject: base: Fix CircularQueue when diffing iterators
......................................................................
base: Fix CircularQueue when diffing iterators
This patch is fixing CircularQueue iterators' behaviour when head and
tail round multiple times.
Change-Id: Ie79ac8accd30a10cf039cf4def87675b01375d6b
Signed-off-by: Giacomo Travaglini <[email protected]>
Reviewed-by: Gabor Dozsa <[email protected]>
---
M src/base/circular_queue.hh
M src/base/circular_queue.test.cc
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/base/circular_queue.hh b/src/base/circular_queue.hh
index 5023661..0451c62 100644
--- a/src/base/circular_queue.hh
+++ b/src/base/circular_queue.hh
@@ -358,7 +358,7 @@
auto ret = _cq->moduloSub(this->_idx, that._idx);
if (ret == 0 && this->_round != that._round) {
- ret += this->_round * _cq->capacity();
+ ret = ((this->_round - that._round) * _cq->capacity());
}
return ret;
}
diff --git a/src/base/circular_queue.test.cc
b/src/base/circular_queue.test.cc
index db59c30..393c520 100644
--- a/src/base/circular_queue.test.cc
+++ b/src/base/circular_queue.test.cc
@@ -241,3 +241,27 @@
ASSERT_EQ(starting_it._idx, ending_it._idx);
ASSERT_TRUE(starting_it != ending_it);
}
+
+/**
+ * Testing correct behaviour when rounding multiple times:
+ * - Round indexes in sync
+ * - Difference between begin() and end() iterator is still
+ * equal to the CircularQueue size.
+ */
+TEST(CircularQueueTest, MultipleRound)
+{
+ const auto cq_size = 8;
+ CircularQueue<uint32_t> cq(cq_size);
+
+ // Filling the queue making it round multiple times
+ auto items_added = cq_size * 3;
+ for (auto idx = 0; idx < items_added; idx++) {
+ cq.push_back(0);
+ }
+
+ auto starting_it = cq.begin();
+ auto ending_it = cq.end();
+
+ ASSERT_EQ(starting_it._round + 1, ending_it._round);
+ ASSERT_EQ(ending_it - starting_it, cq_size);
+}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/17188
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ie79ac8accd30a10cf039cf4def87675b01375d6b
Gerrit-Change-Number: 17188
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Gabor Dozsa <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev