Fix a problem that made valgrind complain on shutdown (not otherwise an issue).

This commit is contained in:
Adam Ierymenko 2015-12-21 15:23:14 -08:00
parent 63a51e2890
commit 16bc9533ed
3 changed files with 11 additions and 6 deletions

View file

@ -37,6 +37,7 @@ DeferredPackets::DeferredPackets(const RuntimeEnvironment *renv) :
RR(renv),
_readPtr(0),
_writePtr(0),
_waiting(0),
_die(false)
{
}
@ -45,8 +46,11 @@ DeferredPackets::~DeferredPackets()
{
_q_m.lock();
_die = true;
_q_m.unlock();
_q_s.post();
while (_waiting > 0) {
_q_m.unlock();
_q_s.post();
_q_m.lock();
}
}
bool DeferredPackets::enqueue(IncomingPacket *pkt)
@ -72,16 +76,16 @@ int DeferredPackets::process()
_q_m.lock();
if (_die) {
_q_m.unlock();
_q_s.post();
return -1;
}
while (_readPtr == _writePtr) {
++_waiting;
_q_m.unlock();
_q_s.wait();
_q_m.lock();
--_waiting;
if (_die) {
_q_m.unlock();
_q_s.post();
return -1;
}
}