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 4 years ago
parent
commit
f197892d4e
2 changed files with 12 additions and 3 deletions
  1. +8
    -1
      locked_queue.hh
  2. +4
    -2
      test_library.cc

+ 8
- 1
locked_queue.hh View File

@ -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
- 2
test_library.cc View File

@ -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";
}
}
}


Loading…
Cancel
Save