* Removed Heartbeat timer

* Implemented a proper update thread
* Removed the UpdateLock Mutex as it's no longer needed because updates can only happen one at a time now.
* This should actually improve performance significantly.. But, see the warning on the next line!
* Warning: If there are deadlocks that the threadpool timer method was hiding, this will expose them for all the nastiness they are.
0.6.0-stable
Teravus Ovares 2008-10-11 11:43:42 +00:00
parent dd5746fb8a
commit abc6424c51
1 changed files with 162 additions and 141 deletions

View File

@ -61,9 +61,10 @@ namespace OpenSim.Region.Environment.Scenes
public SynchronizeSceneHandler SynchronizeScene = null; public SynchronizeSceneHandler SynchronizeScene = null;
public int splitID = 0; public int splitID = 0;
#region Fields #region Fields
protected Timer m_heartbeatTimer = new Timer();
protected Timer m_restartWaitTimer = new Timer(); protected Timer m_restartWaitTimer = new Timer();
protected SimStatsReporter m_statsReporter; protected SimStatsReporter m_statsReporter;
@ -83,7 +84,7 @@ namespace OpenSim.Region.Environment.Scenes
private int m_timePhase = 24; private int m_timePhase = 24;
private readonly Mutex updateLock;
/// <summary> /// <summary>
/// Are we applying physics to any of the prims in this scene? /// Are we applying physics to any of the prims in this scene?
@ -169,6 +170,8 @@ namespace OpenSim.Region.Environment.Scenes
private bool m_scripts_enabled = true; private bool m_scripts_enabled = true;
private string m_defaultScriptEngine; private string m_defaultScriptEngine;
private int m_LastLogin = 0; private int m_LastLogin = 0;
private Thread HeartbeatThread;
private volatile bool shuttingdown = false;
#endregion #endregion
@ -259,7 +262,7 @@ namespace OpenSim.Region.Environment.Scenes
bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion) bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
{ {
m_config = config; m_config = config;
updateLock = new Mutex(false);
m_moduleLoader = moduleLoader; m_moduleLoader = moduleLoader;
m_authenticateHandler = authen; m_authenticateHandler = authen;
CommsManager = commsMan; CommsManager = commsMan;
@ -631,7 +634,8 @@ namespace OpenSim.Region.Environment.Scenes
// Stop all client threads. // Stop all client threads.
ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(true); }); ForEachScenePresence(delegate(ScenePresence avatar) { avatar.ControllingClient.Close(true); });
// Stop updating the scene objects and agents. // Stop updating the scene objects and agents.
m_heartbeatTimer.Close(); //m_heartbeatTimer.Close();
shuttingdown = true;
// close the inner scene // close the inner scene
m_innerScene.Close(); m_innerScene.Close();
// De-register with region communications (events cleanup) // De-register with region communications (events cleanup)
@ -656,10 +660,16 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public void StartTimer() public void StartTimer()
{ {
m_log.Debug("[SCENE]: Starting timer"); //m_log.Debug("[SCENE]: Starting timer");
m_heartbeatTimer.Enabled = true; //m_heartbeatTimer.Enabled = true;
m_heartbeatTimer.Interval = (int)(m_timespan * 1000); //m_heartbeatTimer.Interval = (int)(m_timespan * 1000);
m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); //m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
HeartbeatThread = new Thread(new ParameterizedThreadStart(Heartbeat));
HeartbeatThread.SetApartmentState(ApartmentState.MTA);
HeartbeatThread.Name = "Heartbeat";
HeartbeatThread.Priority = ThreadPriority.AboveNormal;
ThreadTracker.Add(HeartbeatThread);
HeartbeatThread.Start();
} }
/// <summary> /// <summary>
@ -685,7 +695,7 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Heartbeat(object sender, EventArgs e) private void Heartbeat(object sender)
{ {
Update(); Update();
} }
@ -695,9 +705,14 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public override void Update() public override void Update()
{ {
int maintc = 0;
while (!shuttingdown)
{
maintc = System.Environment.TickCount;
TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate; TimeSpan SinceLastFrame = DateTime.Now - m_lastupdate;
// Aquire a lock so only one update call happens at once // Aquire a lock so only one update call happens at once
updateLock.WaitOne(); //updateLock.WaitOne();
float physicsFPS = 0; float physicsFPS = 0;
//m_log.Info("sadfadf" + m_neighbours.Count.ToString()); //m_log.Info("sadfadf" + m_neighbours.Count.ToString());
int agentsInScene = m_innerScene.GetRootAgentCount() + m_innerScene.GetChildAgentCount(); int agentsInScene = m_innerScene.GetRootAgentCount() + m_innerScene.GetChildAgentCount();
@ -822,7 +837,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
finally finally
{ {
updateLock.ReleaseMutex(); //updateLock.ReleaseMutex();
// Get actual time dilation // Get actual time dilation
float tmpval = (m_timespan / (float)SinceLastFrame.TotalSeconds); float tmpval = (m_timespan / (float)SinceLastFrame.TotalSeconds);
@ -836,6 +851,12 @@ namespace OpenSim.Region.Environment.Scenes
m_lastupdate = DateTime.Now; m_lastupdate = DateTime.Now;
} }
maintc = System.Environment.TickCount - maintc;
maintc = (int)(m_timespan * 1000) - maintc;
if ((maintc < (m_timespan * 1000)) && maintc > 0)
Thread.Sleep(maintc);
}
} }
private void SendSimStatsPackets(SimStats stats) private void SendSimStatsPackets(SimStats stats)