diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs index 391326fb3f..468dccf67b 100644 --- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs +++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs @@ -28,10 +28,12 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Threading; using Nini.Config; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.Monitoring; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -45,9 +47,14 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer private Scene m_scene; private Dictionary NewFiles = new Dictionary(); private Dictionary Transfers = new Dictionary(); - private double lastFilesExpire = 0; private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private object timeTickLock = new object(); + private double lastTimeTick = 0.0; + private bool inTimeTick = false; + private double lastFilesExpire = 0.0; + public struct XferRequest { public IClientAPI remoteClient; @@ -67,20 +74,22 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer public void Initialise(IConfigSource config) { - lastFilesExpire = Util.GetTimeStampMS() + 300000.0; + lastTimeTick = Util.GetTimeStampMS() + 30000.0; + lastFilesExpire = lastTimeTick + 180000.0; } public void AddRegion(Scene scene) { m_scene = scene; m_scene.EventManager.OnNewClient += NewClient; - + m_scene.EventManager.OnRegionHeartbeatEnd += OnTimeTick; m_scene.RegisterModuleInterface(this); } public void RemoveRegion(Scene scene) { m_scene.EventManager.OnNewClient -= NewClient; + m_scene.EventManager.OnRegionHeartbeatEnd -= OnTimeTick; m_scene.UnregisterModuleInterface(this); m_scene = null; @@ -106,6 +115,35 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer #endregion + public void OnTimeTick(Scene scene) + { + // we are on a heartbeat thread we there can be several + if(Monitor.TryEnter(timeTickLock)) + { + if(!inTimeTick) + { + double now = Util.GetTimeStampMS(); + if(now - lastTimeTick > 1500.0) // 1.5 second + { + inTimeTick = true; + + //don't overload busy heartbeat + WorkManager.RunInThread( + delegate + { + transfersTimeTick(now); + expireFiles(now); + + lastTimeTick = now; + inTimeTick = false; + }, + null, + "XferTimeTick"); + } + } + Monitor.Exit(timeTickLock); + } + } #region IXfer Members /// @@ -135,26 +173,31 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer fd.timeStampMS = now; NewFiles.Add(fileName, fd); } + } + return true; + } - // lazy expires hopefully we will not have many files so nasty code will do it - if(now - lastFilesExpire > 180000.0) + #endregion + public void expireFiles(double now) + { + lock (NewFiles) + { + // hopefully we will not have many files so nasty code will do it + if(now - lastFilesExpire > 120000.0) { lastFilesExpire = now; List expires = new List(); foreach(string fname in NewFiles.Keys) { - if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 180000.0) + if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 120000.0) expires.Add(fname); } foreach(string fname in expires) NewFiles.Remove(fname); } } - return true; } - #endregion - public void NewClient(IClientAPI client) { client.OnRequestXfer += RequestXfer; @@ -162,6 +205,11 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer client.OnAbortXfer += AbortXfer; } + public void transfersTimeTick(double now) + { + + } + /// /// ///