better have a lock

0.9.1.0-post-fixes
UbitUmarov 2018-10-08 18:53:30 +01:00
parent 57ec0d3884
commit 235dd37b9c
1 changed files with 23 additions and 19 deletions

View File

@ -6856,33 +6856,37 @@ namespace OpenSim.Region.Framework.Scenes
private int m_bandwidthBurst = 20000;
private int m_bytesControl;
private double m_lastBandwithTime;
private object m_throttleLock = new object();
public bool CapCanSendAsset(int type, int size)
{
if(size == 0)
return true;
if(type > 1)
lock (m_throttleLock)
{
// not texture or mesh
m_bytesControl -= size;
return true;
}
if (type > 1)
{
// not texture or mesh
m_bytesControl -= size;
return true;
}
double currenttime = Util.GetTimeStamp();
double timeElapsed = currenttime - m_lastBandwithTime;
if (timeElapsed > .05)
{
m_lastBandwithTime = currenttime;
int add = (int)(m_bandwidth * timeElapsed);
m_bytesControl += add;
if (m_bytesControl > m_bandwidthBurst)
m_bytesControl = m_bandwidthBurst;
}
if (m_bytesControl > 0 )
{
m_bytesControl -= size;
return true;
double currenttime = Util.GetTimeStamp();
double timeElapsed = currenttime - m_lastBandwithTime;
if (timeElapsed > .02)
{
m_lastBandwithTime = currenttime;
int add = (int)(m_bandwidth * timeElapsed);
m_bytesControl += add;
if (m_bytesControl > m_bandwidthBurst)
m_bytesControl = m_bandwidthBurst;
}
if (m_bytesControl > 0 )
{
m_bytesControl -= size;
return true;
}
}
return false;
}