From 393b4ee9cc33a36c926531967fff35d829ab3e7c Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 14 Nov 2024 13:27:52 -0500 Subject: [PATCH] Sequence: Comparator must provide a strict ordering We have to provide our own check for equal based on the provided comparator. Signed-off-by: Joseph Schuchart --- ttg/ttg/constraint.h | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/ttg/ttg/constraint.h b/ttg/ttg/constraint.h index dc1926204..1c353702f 100644 --- a/ttg/ttg/constraint.h +++ b/ttg/ttg/constraint.h @@ -65,7 +65,7 @@ namespace ttg { template, + typename Compare = std::less, typename Mapper = ttg::Void> struct SequencedKeysConstraint : public ConstraintBase { @@ -95,9 +95,17 @@ namespace ttg { } }; + bool comp_equal(const Ordinal& a, const Ordinal& b) const { + return (!m_order(a, b) && !m_order(b, a)); + } + + bool eligible(const Ordinal& ord) const { + return m_order(ord, m_current) || comp_equal(ord, m_current); + } + bool check_key_impl(const key_type& key, Ordinal ord, ttg::TTBase *tt) { if (!m_stopped) { - if (m_order(ord, m_current)) { + if (eligible(ord)) { // key should be executed if (m_auto_release) { // only needed for auto-release m_active.fetch_add(1, std::memory_order_relaxed); @@ -117,7 +125,7 @@ namespace ttg { } // key should be deferred auto g = this->lock_guard(); - if (!m_stopped && m_order(ord, m_current)) { + if (!m_stopped && eligible(ord)) { // someone released this ordinal while we took the lock return true; } @@ -176,7 +184,7 @@ namespace ttg { this->m_current = ord; return; } - if (!force_check && m_order(ord, this->m_current)) { + if (!force_check && eligible(ord)) { return; // already at the provided ordinal, nothing to be done } // trigger the next sequence(s) (m_sequence is ordered by ordinal) @@ -185,14 +193,12 @@ namespace ttg { auto g = this->lock_guard(); // set current ordinal this->m_current = ord; - { - for (auto it = this->m_sequence.begin(); it != this->m_sequence.end();) { - if (!this->m_order(it->first, this->m_current)) break; - // extract the next sequence - this->m_current = it->first; - seqs.push_back(std::move(it->second)); - it = this->m_sequence.erase(it); - } + for (auto it = this->m_sequence.begin(); it != this->m_sequence.end();) { + if (!eligible(it->first)) break; + // extract the next sequence + this->m_current = it->first; + seqs.push_back(std::move(it->second)); + it = this->m_sequence.erase(it); } } for (auto& elem : seqs) { @@ -351,7 +357,7 @@ namespace ttg { -> SequencedKeysConstraint< std::decay_t>>, std::decay_t>, - std::less_equal>>, + std::less>>, std::enable_if_t>>>, Mapper> >; @@ -360,7 +366,7 @@ namespace ttg { -> SequencedKeysConstraint< std::decay_t>>, std::decay_t>, - std::less_equal>>, + std::less>>, std::enable_if_t>>>, Mapper> >;