From b2ed348aa2746fbf034b713d006e40366c479d5a Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 12:33:23 -0700 Subject: Implemented a Watchdog class. Do not manually create Thread objects anymore, use Watchdog.StartThread(). While your thread is running call Watchdog.UpdateThread(). When it is shutting down call Watchdog.RemoveThread(). Most of the threads in OpenSim have been updated --- .../Agent/InternetRelayClientView/Server/IRCClientView.cs | 10 ++++++---- .../Agent/InternetRelayClientView/Server/IRCServer.cs | 7 +++++-- .../OptionalModules/ContentManagementSystem/CMController.cs | 10 +++++----- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/OptionalModules') diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index df03b8d..4b0d01a 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -67,9 +67,8 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server { m_client = client; m_scene = scene; - - Thread loopThread = new Thread(InternalLoop); - loopThread.Start(); + + Watchdog.StartThread(InternalLoop, "IRCClientView", ThreadPriority.Normal, false); } private void SendServerCommand(string command) @@ -102,7 +101,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server { try { - string strbuf = ""; + string strbuf = String.Empty; while (m_connected && m_client.Connected) { @@ -140,6 +139,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server } Thread.Sleep(0); + Watchdog.UpdateThread(); } } catch (IOException) @@ -156,6 +156,8 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server m_log.Warn("[IRCd] Disconnected client."); } + + Watchdog.RemoveThread(); } private void ProcessInMessage(string message, string command) diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCServer.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCServer.cs index 91ce9f1..eb39026 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCServer.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCServer.cs @@ -33,6 +33,7 @@ using System.Reflection; using System.Text; using System.Threading; using log4net; +using OpenSim.Framework; using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server @@ -56,8 +57,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server m_listener.Start(50); - Thread thread = new Thread(ListenLoop); - thread.Start(); + Watchdog.StartThread(ListenLoop, "IRCServer", ThreadPriority.Normal, false); m_baseScene = baseScene; } @@ -72,7 +72,10 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server while (m_running) { AcceptClient(m_listener.AcceptTcpClient()); + Watchdog.UpdateThread(); } + + Watchdog.RemoveThread(); } private void AcceptClient(TcpClient client) diff --git a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs index 16fe9e9..8d6c41d 100644 --- a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs +++ b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs @@ -86,7 +86,6 @@ namespace OpenSim.Region.OptionalModules.ContentManagement /// Hashtable m_sceneList = Hashtable.Synchronized(new Hashtable()); State m_state = State.NONE; - Thread m_thread = null; CMView m_view = null; #endregion Fields @@ -148,10 +147,7 @@ namespace OpenSim.Region.OptionalModules.ContentManagement lock (this) { m_estateModule = scene.RequestModuleInterface(); - m_thread = new Thread(MainLoop); - m_thread.Name = "Content Management"; - m_thread.IsBackground = true; - m_thread.Start(); + Watchdog.StartThread(MainLoop, "Content Management", ThreadPriority.Normal, true); m_state = State.NONE; } } @@ -200,6 +196,8 @@ namespace OpenSim.Region.OptionalModules.ContentManagement m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- uuuuuuuuuh, what?"); break; } + + Watchdog.UpdateThread(); } } catch (Exception e) @@ -209,6 +207,8 @@ namespace OpenSim.Region.OptionalModules.ContentManagement "[CONTENT MANAGEMENT]: Content management thread terminating with exception. PLEASE REBOOT YOUR SIM - CONTENT MANAGEMENT WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}", e); } + + Watchdog.RemoveThread(); } /// -- cgit v1.1