diff --git a/include/base_queue_wait.h b/include/base_queue_wait.h index e4bfeb2..fc80d17 100644 --- a/include/base_queue_wait.h +++ b/include/base_queue_wait.h @@ -297,12 +297,14 @@ namespace small { // inline small::WaitFlags test_and_get(T *elem, TimePoint *time_wait_until) { - *time_wait_until = TimeClock::now() + std::chrono::minutes(60); - auto ret = m_parent_caller.test_and_get(elem, time_wait_until); + *time_wait_until = TimeClock::now() + std::chrono::minutes(60); + bool is_empty_after_get = false; + + auto ret = m_parent_caller.test_and_get(elem, time_wait_until, &is_empty_after_get); auto is_exit_ret = ret == small::WaitFlags::kExit_Force || ret == small::WaitFlags::kExit_When_Done; // notify condition if q is empty or exit force - if (is_exit_ret || is_empty_queue()) { + if (is_exit_ret || is_empty_after_get) { m_queues_exit_condition.notify_all(); } diff --git a/include/lock_queue.h b/include/lock_queue.h index 67ffccf..e5b6805 100644 --- a/include/lock_queue.h +++ b/include/lock_queue.h @@ -238,8 +238,10 @@ namespace small { // // check for front element // - inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint * /* time_wait_until */) + inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint * /* time_wait_until */, bool *is_empty_after_get) { + *is_empty_after_get = true; + if (is_exit_force()) { return small::WaitFlags::kExit_Force; } @@ -260,6 +262,8 @@ namespace small { } m_queue.pop_front(); + *is_empty_after_get = m_queue.empty(); + return small::WaitFlags::kElement; } diff --git a/include/prio_queue.h b/include/prio_queue.h index 7262dc5..ad33ab6 100644 --- a/include/prio_queue.h +++ b/include/prio_queue.h @@ -426,8 +426,10 @@ namespace small { } // extract from queue - inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint * /* time_wait_until */) + inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint * /* time_wait_until */, bool *is_empty_after_get) { + *is_empty_after_get = true; + if (is_exit_force()) { return small::WaitFlags::kExit_Force; } @@ -470,7 +472,9 @@ namespace small { } // get elem - return pop_front(*queue, elem); + auto ret = pop_front(*queue, elem); + *is_empty_after_get = empty(); + return ret; } // reset all stats @@ -482,7 +486,9 @@ namespace small { ++prev_stats.m_count_executed; // get elem - return pop_front(queue, elem); + auto ret = pop_front(queue, elem); + *is_empty_after_get = empty(); + return ret; } // here all queues are empty diff --git a/include/time_queue.h b/include/time_queue.h index bdaa05f..441fde0 100644 --- a/include/time_queue.h +++ b/include/time_queue.h @@ -336,8 +336,10 @@ namespace small { // friend BaseQueueWait; - inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint *time_wait_until) + inline small::WaitFlags test_and_get(T *elem, typename BaseQueueWait::TimePoint *time_wait_until, bool *is_empty_after_get) { + *is_empty_after_get = true; + if (is_exit_force()) { return small::WaitFlags::kExit_Force; } @@ -357,6 +359,7 @@ namespace small { // check time *time_wait_until = get_next_time(); if (*time_wait_until > TimeClock::now()) { + *is_empty_after_get = false; return small::WaitFlags::kWait; } @@ -366,6 +369,8 @@ namespace small { } m_queue.pop(); + *is_empty_after_get = m_queue.empty(); + return small::WaitFlags::kElement; }