From dde0814837866e5c27cd5c97be0461bdca481bc2 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 16 Mar 2019 00:30:15 -0400 Subject: Use MultiLevelQueue instead of old ThreadQueueList --- src/common/multi_level_queue.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/common/multi_level_queue.h') diff --git a/src/common/multi_level_queue.h b/src/common/multi_level_queue.h index fc72a8238..d56ab6531 100644 --- a/src/common/multi_level_queue.h +++ b/src/common/multi_level_queue.h @@ -107,6 +107,9 @@ public: iterator_impl(const iterator_impl& other) : mlq(other.mlq), it(other.it), current_priority(other.current_priority) {} + iterator_impl(const iterator_impl& other) + : mlq(other.mlq), it(other.it), current_priority(other.current_priority) {} + iterator_impl& operator=(const iterator_impl& other) { mlq = other.mlq; it = other.it; @@ -149,7 +152,7 @@ public: using iterator = iterator_impl; using const_iterator = iterator_impl; - void add(T& element, u32 priority, bool send_back = true) { + void add(const T& element, u32 priority, bool send_back = true) { if (send_back) levels[priority].push_back(element); else @@ -158,23 +161,18 @@ public: } void remove(const T& element, u32 priority) { - levels[priority].erase(ListIterateTo(levels[priority], element)); + auto it = ListIterateTo(levels[priority], element); + if (it == levels[priority].end()) + return; + levels[priority].erase(it); if (levels[priority].empty()) { used_priorities &= ~(1ULL << priority); } } void adjust(const T& element, u32 old_priority, u32 new_priority, bool adjust_front = false) { - const auto new_next = - adjust_front ? levels[new_priority].cbegin() : levels[new_priority].cend(); - ListSplice(levels[new_priority], new_next, levels[old_priority], - ListIterateTo(levels[old_priority], element)); - - used_priorities |= 1ULL << new_priority; - - if (levels[old_priority].empty()) { - used_priorities &= ~(1ULL << old_priority); - } + remove(element, old_priority); + add(element, new_priority, !adjust_front); } void adjust(const_iterator it, u32 old_priority, u32 new_priority, bool adjust_front = false) { adjust(*it, old_priority, new_priority, adjust_front); -- cgit v1.2.3