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

This commit is contained in:
John Hurliman
2009-10-22 12:33:23 -07:00
parent 11013ad295
commit b2ed348aa2
17 changed files with 309 additions and 123 deletions

View File

@@ -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();
}
}

View File

@@ -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
/// <summary>
/// Perform the callback on the original requester of the assets
/// </summary>
protected void PerformAssetsRequestCallback()
protected void PerformAssetsRequestCallback(object o)
{
try
{

View File

@@ -74,7 +74,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private Dictionary<ulong, int> m_blacklistedregions = new Dictionary<ulong, int>();
private Dictionary<ulong, string> m_cachedRegionMapItemsAddress = new Dictionary<ulong, string>();
private List<UUID> m_rootAgents = new List<UUID>();
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);
}
/// <summary>
@@ -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();
}
/// <summary>