From bb529a226d8fd6914c35ddefca05e96c4ca62cac Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 1 Feb 2014 02:27:21 +0200 Subject: [PATCH] queue clear - operator=(&&) --- include/c11log/details/blocking_queue.h | 7 +++++-- src/test.cpp | 9 +-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/c11log/details/blocking_queue.h b/include/c11log/details/blocking_queue.h index 4d380707..92a3ca63 100644 --- a/include/c11log/details/blocking_queue.h +++ b/include/c11log/details/blocking_queue.h @@ -95,8 +95,11 @@ public: // Clear the queue void clear() { - T item; - while (pop(item, std::chrono::milliseconds(0))); + { + std::unique_lock ul(mutex_); + q_ = queue_t{}; + } + item_popped_cond_.notify_all(); } private: diff --git a/src/test.cpp b/src/test.cpp index 99fd892d..58e143af 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -70,7 +70,7 @@ void popper(Q* q) string output; while(active) { - q->pop(output); + q->pop(output); ++pop_count; } } @@ -80,13 +80,6 @@ void testq(int size, int pushers, int poppers) active = true; Q q{static_cast(size)}; - /* - A a; - q.push(a); - std::cout << "Befor pop..\n"; - q.pop(a); - return; - */ for(int i = 0; i < poppers; i++) new std::thread(std::bind(popper, &q));