Browse Source

Sorry, but I do need that Deleter feature in the locked_queue to avoid memory leaks. But this way now it should not harm all non-users, I hope so. :-o

sync
Roker 7 years ago
parent
commit
f197892d4e
  1. 9
      locked_queue.hh
  2. 4
      test_library.cc

9
locked_queue.hh

@ -9,7 +9,7 @@
namespace utility
{
template<class T>
template<class T, void(*Deleter)(T) = nullptr>
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();
}

4
test_library.cc

@ -50,7 +50,8 @@ void consumer_thread()
int sum = 0;
while(keep_running)
{
auto q = pc.get_changed(); // might block, that is okay.
for(auto& q : pc)
{
switch(q.state())
{
case PC_State::Created:
@ -86,6 +87,7 @@ void consumer_thread()
default: throw "Illegal state";
}
}
}
std::cout << "Consumer sum: " << sum << ".\n";
}

Loading…
Cancel
Save