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
---
.../CoreModules/InterGrid/OpenGridProtocolModule.cs | 15 ++++++++++-----
.../Region/CoreModules/World/Archiver/AssetsRequest.cs | 8 +++-----
.../Region/CoreModules/World/WorldMap/WorldMapModule.cs | 13 ++++++-------
3 files changed, 19 insertions(+), 17 deletions(-)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs b/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
index d636b1c..62500a2 100644
--- a/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
+++ b/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
@@ -1208,10 +1208,7 @@ namespace OpenSim.Region.CoreModules.InterGrid
if (homeScene.TryGetAvatar(avatarId,out avatar))
{
KillAUser ku = new KillAUser(avatar,mod);
- Thread ta = new Thread(ku.ShutdownNoLogout);
- ta.IsBackground = true;
- ta.Name = "ShutdownThread";
- ta.Start();
+ Watchdog.StartThread(ku.ShutdownNoLogout, "OGPShutdown", ThreadPriority.Normal, true);
}
}
@@ -1261,7 +1258,13 @@ namespace OpenSim.Region.CoreModules.InterGrid
avToBeKilled.ControllingClient.SendLogoutPacketWhenClosing = false;
- Thread.Sleep(30000);
+ int sleepMS = 30000;
+ while (sleepMS > 0)
+ {
+ Watchdog.UpdateThread();
+ Thread.Sleep(1000);
+ sleepMS -= 1000;
+ }
// test for child agent because they might have come back
if (avToBeKilled.IsChildAgent)
@@ -1270,6 +1273,8 @@ namespace OpenSim.Region.CoreModules.InterGrid
avToBeKilled.ControllingClient.Close();
}
}
+
+ Watchdog.RemoveThread();
}
}
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
index fe9c8d9..c9fce91 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
@@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (m_repliesRequired == 0)
{
m_requestState = RequestState.Completed;
- PerformAssetsRequestCallback();
+ PerformAssetsRequestCallback(null);
return;
}
@@ -246,9 +246,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
// We want to stop using the asset cache thread asap
// as we now need to do the work of producing the rest of the archive
- Thread newThread = new Thread(PerformAssetsRequestCallback);
- newThread.Name = "OpenSimulator archiving thread post assets receipt";
- newThread.Start();
+ Util.FireAndForget(PerformAssetsRequestCallback);
}
else
{
@@ -265,7 +263,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
///
/// Perform the callback on the original requester of the assets
///
- protected void PerformAssetsRequestCallback()
+ protected void PerformAssetsRequestCallback(object o)
{
try
{
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index 4e40084..a4bcbad 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -74,7 +74,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private Dictionary m_blacklistedregions = new Dictionary();
private Dictionary m_cachedRegionMapItemsAddress = new Dictionary();
private List m_rootAgents = new List();
- private Thread mapItemReqThread;
private volatile bool threadrunning = false;
//private int CacheRegionsDistance = 256;
@@ -338,13 +337,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
{
if (threadrunning) return;
threadrunning = true;
+
m_log.Debug("[WORLD MAP]: Starting remote MapItem request thread");
- mapItemReqThread = new Thread(new ThreadStart(process));
- mapItemReqThread.IsBackground = true;
- mapItemReqThread.Name = "MapItemRequestThread";
- mapItemReqThread.Priority = ThreadPriority.BelowNormal;
- mapItemReqThread.SetApartmentState(ApartmentState.MTA);
- mapItemReqThread.Start();
+
+ Watchdog.StartThread(process, "MapItemRequestThread", ThreadPriority.BelowNormal, true);
}
///
@@ -461,6 +457,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
OSDMap response = RequestMapItemsAsync("", st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle);
RequestMapItemsCompleted(response);
}
+
+ Watchdog.UpdateThread();
}
}
catch (Exception e)
@@ -469,6 +467,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
}
threadrunning = false;
+ Watchdog.RemoveThread();
}
///
--
cgit v1.1