mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-04 20:34:26 -04:00
added mutex protection around pqistreamer::getRates, since float r/w are not necessarily atomic
This commit is contained in:
parent
eba90a83c6
commit
0d1d31a25f
3 changed files with 105 additions and 82 deletions
|
@ -83,35 +83,35 @@ public:
|
|||
:bw_in(0), bw_out(0), bwMax_in(0), bwMax_out(0),
|
||||
bwCapEnabled(false), bwCap_in(0), bwCap_out(0) { return; }
|
||||
|
||||
virtual ~RateInterface() { return; }
|
||||
virtual ~RateInterface() { return; }
|
||||
|
||||
virtual void getRates(RsBwRates &rates)
|
||||
{
|
||||
virtual void getRates(RsBwRates &rates)
|
||||
{
|
||||
rates.mRateIn = bw_in;
|
||||
rates.mRateOut = bw_out;
|
||||
rates.mMaxRateIn = bwMax_in;
|
||||
rates.mMaxRateOut = bwMax_out;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
virtual int gatherStatistics(std::list<RSTrafficClue>& /* outqueue_lst */,std::list<RSTrafficClue>& /* inqueue_lst */) { return 0;}
|
||||
|
||||
virtual int getQueueSize(bool /* in */) { return 0;}
|
||||
virtual float getRate(bool in)
|
||||
virtual int getQueueSize(bool /* in */) { return 0;}
|
||||
virtual float getRate(bool in)
|
||||
{
|
||||
if (in)
|
||||
return bw_in;
|
||||
return bw_out;
|
||||
}
|
||||
|
||||
virtual float getMaxRate(bool in)
|
||||
virtual float getMaxRate(bool in)
|
||||
{
|
||||
if (in)
|
||||
return bwMax_in;
|
||||
return bwMax_out;
|
||||
}
|
||||
|
||||
virtual void setMaxRate(bool in, float val)
|
||||
virtual void setMaxRate(bool in, float val)
|
||||
{
|
||||
if (in)
|
||||
{
|
||||
|
@ -140,8 +140,8 @@ virtual void setMaxRate(bool in, float val)
|
|||
}
|
||||
|
||||
|
||||
virtual void setRateCap(float val_in, float val_out)
|
||||
{
|
||||
virtual void setRateCap(float val_in, float val_out)
|
||||
{
|
||||
if ((val_in == 0) && (val_out == 0))
|
||||
{
|
||||
#ifdef DEBUG_RATECAP
|
||||
|
@ -160,11 +160,11 @@ virtual void setRateCap(float val_in, float val_out)
|
|||
bwCap_out = val_out;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void setRate(bool in, float val)
|
||||
virtual void setRate(bool in, float val)
|
||||
{
|
||||
if (in)
|
||||
bw_in = val;
|
||||
|
@ -173,10 +173,10 @@ void setRate(bool in, float val)
|
|||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
float bw_in, bw_out, bwMax_in, bwMax_out;
|
||||
bool bwCapEnabled;
|
||||
float bwCap_in, bwCap_out;
|
||||
private:
|
||||
float bw_in, bw_out, bwMax_in, bwMax_out;
|
||||
bool bwCapEnabled;
|
||||
float bwCap_in, bwCap_out;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -77,6 +77,13 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi
|
|||
mCurrRead(0), mCurrSent(0),
|
||||
mAvgReadCount(0), mAvgSentCount(0)
|
||||
{
|
||||
|
||||
// 100 B/s (minimal)
|
||||
setMaxRate(true, 0.1);
|
||||
setMaxRate(false, 0.1);
|
||||
setRate(true, 0); // needs to be off-mutex
|
||||
setRate(false, 0);
|
||||
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
mAcceptsPacketSlicing = false ; // by default. Will be turned into true when everyone's ready.
|
||||
|
@ -91,12 +98,6 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi
|
|||
mPkt_rpending = 0;
|
||||
mReading_state = reading_state_initial ;
|
||||
|
||||
// 100 B/s (minimal)
|
||||
setMaxRate(true, 0.1);
|
||||
setMaxRate(false, 0.1);
|
||||
setRate(true, 0);
|
||||
setRate(false, 0);
|
||||
|
||||
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, "pqistreamer::pqistreamer() Initialisation!");
|
||||
|
||||
if (!bio_in)
|
||||
|
@ -195,6 +196,22 @@ RsItem *pqistreamer::GetItem()
|
|||
return osr;
|
||||
}
|
||||
|
||||
float pqistreamer::getRate(bool b)
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
return RateInterface::getRate(b) ;
|
||||
}
|
||||
void pqistreamer::setMaxRate(bool b,float f)
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
RateInterface::setMaxRate(b,f) ;
|
||||
}
|
||||
void pqistreamer::setRate(bool b,float f)
|
||||
{
|
||||
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
||||
RateInterface::setRate(b,f) ;
|
||||
}
|
||||
|
||||
void pqistreamer::updateRates()
|
||||
{
|
||||
// now update rates both ways.
|
||||
|
|
|
@ -67,6 +67,12 @@ class pqistreamer: public PQInterface
|
|||
virtual void getRates(RsBwRates &rates);
|
||||
virtual int getQueueSize(bool in); // extracting data.
|
||||
virtual int gatherStatistics(std::list<RSTrafficClue>& outqueue_stats,std::list<RSTrafficClue>& inqueue_stats); // extracting data.
|
||||
|
||||
// mutex protected versions of RateInterface calls.
|
||||
virtual void setRate(bool b,float f) ;
|
||||
virtual void setMaxRate(bool b,float f) ;
|
||||
virtual float getRate(bool b) ;
|
||||
|
||||
protected:
|
||||
|
||||
int tick_bio();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue