diff --git a/locked_queue.hh b/locked_queue.hh index a84cfdb..970b1f1 100644 --- a/locked_queue.hh +++ b/locked_queue.hh @@ -9,7 +9,7 @@ namespace utility { - template + template class locked_queue { typedef std::recursive_mutex Mutex; @@ -28,6 +28,13 @@ namespace utility void clear() { Lock L(_mtx); + if(Deleter != nullptr) + { + for(auto q : _q) + { + Deleter(q); + } + } _q.clear(); } diff --git a/test_library.cc b/test_library.cc index aa20382..3b5a56f 100644 --- a/test_library.cc +++ b/test_library.cc @@ -50,9 +50,10 @@ void consumer_thread() int sum = 0; while(keep_running) { - auto q = pc.get_changed(); // might block, that is okay. - switch(q.state()) + for(auto& q : pc) { + switch(q.state()) + { case PC_State::Created: { const int value = atoi( q.pdata->data ); @@ -84,6 +85,7 @@ void consumer_thread() break; } default: throw "Illegal state"; + } } }