From 235dd37b9c6e158ad201d49a2414ce84648bcb86 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 8 Oct 2018 18:53:30 +0100 Subject: [PATCH] better have a lock --- .../Region/Framework/Scenes/ScenePresence.cs | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index bcae69f108..3312ace2cc 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -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; }