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

View File

@ -88,7 +88,8 @@ private:
const RuntimeEnvironment *const RR;
unsigned long _readPtr;
unsigned long _writePtr;
bool _die;
volatile int _waiting;
volatile bool _die;
Mutex _q_m;
BinarySemaphore _q_s;
};

View File

@ -66,7 +66,7 @@ public:
#ifdef ZT_ENABLE_CLUSTER
,cluster((Cluster *)0)
#endif
,dpEnabled(false)
,dpEnabled(0)
{
}