added mutex proteciton around mAvgLastUpdate to avoid it being changed by the constructor

This commit is contained in:
csoler 2016-06-11 09:50:22 -04:00
parent 0d1d31a25f
commit 23e8e932be

View File

@ -218,10 +218,14 @@ void pqistreamer::updateRates()
time_t t = time(NULL); // get current timestep. time_t t = time(NULL); // get current timestep.
if (t > mAvgLastUpdate + PQISTREAM_AVG_PERIOD)
{ {
int64_t diff = int64_t(t) - int64_t(mAvgLastUpdate) ; RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
diff = int64_t(t) - int64_t(mAvgLastUpdate) ;
}
if (diff > PQISTREAM_AVG_PERIOD)
{
float avgReadpSec = getRate(true ) * PQISTREAM_AVG_FRAC + (1.0 - PQISTREAM_AVG_FRAC) * mAvgReadCount/(1000.0 * float(diff)); float avgReadpSec = getRate(true ) * PQISTREAM_AVG_FRAC + (1.0 - PQISTREAM_AVG_FRAC) * mAvgReadCount/(1000.0 * float(diff));
float avgSentpSec = getRate(false) * PQISTREAM_AVG_FRAC + (1.0 - PQISTREAM_AVG_FRAC) * mAvgSentCount/(1000.0 * float(diff)); float avgSentpSec = getRate(false) * PQISTREAM_AVG_FRAC + (1.0 - PQISTREAM_AVG_FRAC) * mAvgSentCount/(1000.0 * float(diff));
@ -243,11 +247,14 @@ void pqistreamer::updateRates()
setRate(false, 0); setRate(false, 0);
} }
{
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
mAvgLastUpdate = t; mAvgLastUpdate = t;
mAvgReadCount = 0; mAvgReadCount = 0;
mAvgSentCount = 0; mAvgSentCount = 0;
} }
} }
}
int pqistreamer::tick_bio() int pqistreamer::tick_bio()
{ {