aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Communications/RestClient.cs2
-rw-r--r--OpenSim/Framework/Parallel.cs6
-rw-r--r--OpenSim/Framework/Util.cs64
-rw-r--r--OpenSim/Grid/MessagingServer.Modules/MessageService.cs3
-rw-r--r--OpenSim/Region/Application/OpenSim.cs9
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs6
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs2
-rw-r--r--bin/OpenSim.ini.example9
9 files changed, 81 insertions, 28 deletions
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs
index 317b3a0..97b3b60 100644
--- a/OpenSim/Framework/Communications/RestClient.cs
+++ b/OpenSim/Framework/Communications/RestClient.cs
@@ -403,7 +403,7 @@ namespace OpenSim.Framework.Communications
403 /// In case, we are invoked asynchroneously this object will keep track of the state 403 /// In case, we are invoked asynchroneously this object will keep track of the state
404 /// </summary> 404 /// </summary>
405 AsyncResult<Stream> ar = new AsyncResult<Stream>(callback, state); 405 AsyncResult<Stream> ar = new AsyncResult<Stream>(callback, state);
406 ThreadPool.UnsafeQueueUserWorkItem(RequestHelper, ar); 406 Util.FireAndForget(RequestHelper, ar);
407 return ar; 407 return ar;
408 } 408 }
409 409
diff --git a/OpenSim/Framework/Parallel.cs b/OpenSim/Framework/Parallel.cs
index ab2e108..70eecdc 100644
--- a/OpenSim/Framework/Parallel.cs
+++ b/OpenSim/Framework/Parallel.cs
@@ -66,7 +66,7 @@ namespace OpenSim.Framework
66 66
67 for (int i = 0; i < threadCount; i++) 67 for (int i = 0; i < threadCount; i++)
68 { 68 {
69 ThreadPool.UnsafeQueueUserWorkItem( 69 Util.FireAndForget(
70 delegate(object o) 70 delegate(object o)
71 { 71 {
72 int threadIndex = (int)o; 72 int threadIndex = (int)o;
@@ -122,7 +122,7 @@ namespace OpenSim.Framework
122 122
123 for (int i = 0; i < threadCount; i++) 123 for (int i = 0; i < threadCount; i++)
124 { 124 {
125 ThreadPool.UnsafeQueueUserWorkItem( 125 Util.FireAndForget(
126 delegate(object o) 126 delegate(object o)
127 { 127 {
128 int threadIndex = (int)o; 128 int threadIndex = (int)o;
@@ -178,7 +178,7 @@ namespace OpenSim.Framework
178 178
179 for (int i = 0; i < threadCount; i++) 179 for (int i = 0; i < threadCount; i++)
180 { 180 {
181 ThreadPool.UnsafeQueueUserWorkItem( 181 Util.FireAndForget(
182 delegate(object o) 182 delegate(object o)
183 { 183 {
184 int threadIndex = (int)o; 184 int threadIndex = (int)o;
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 7dde6dd..d09bd6d 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -53,6 +53,18 @@ using Amib.Threading;
53namespace OpenSim.Framework 53namespace OpenSim.Framework
54{ 54{
55 /// <summary> 55 /// <summary>
56 /// The method used by Util.FireAndForget for asynchronously firing events
57 /// </summary>
58 public enum FireAndForgetMethod
59 {
60 UnsafeQueueUserWorkItem,
61 QueueUserWorkItem,
62 BeginInvoke,
63 SmartThreadPool,
64 Thread,
65 }
66
67 /// <summary>
56 /// Miscellaneous utility functions 68 /// Miscellaneous utility functions
57 /// </summary> 69 /// </summary>
58 public class Util 70 public class Util
@@ -74,7 +86,9 @@ namespace OpenSim.Framework
74 86
75 public static readonly Regex UUIDPattern 87 public static readonly Regex UUIDPattern
76 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); 88 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
77 89
90 public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
91
78 /// <summary> 92 /// <summary>
79 /// Linear interpolates B<->C using percent A 93 /// Linear interpolates B<->C using percent A
80 /// </summary> 94 /// </summary>
@@ -1277,7 +1291,7 @@ namespace OpenSim.Framework
1277 /// <summary> 1291 /// <summary>
1278 /// Created to work around a limitation in Mono with nested delegates 1292 /// Created to work around a limitation in Mono with nested delegates
1279 /// </summary> 1293 /// </summary>
1280 /*private class FireAndForgetWrapper 1294 private class FireAndForgetWrapper
1281 { 1295 {
1282 public void FireAndForget(System.Threading.WaitCallback callback) 1296 public void FireAndForget(System.Threading.WaitCallback callback)
1283 { 1297 {
@@ -1288,17 +1302,28 @@ namespace OpenSim.Framework
1288 { 1302 {
1289 callback.BeginInvoke(obj, EndFireAndForget, callback); 1303 callback.BeginInvoke(obj, EndFireAndForget, callback);
1290 } 1304 }
1291 }*/ 1305
1306 private static void EndFireAndForget(IAsyncResult ar)
1307 {
1308 System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState;
1309
1310 try { callback.EndInvoke(ar); }
1311 catch (Exception ex) { m_log.Error("[UTIL]: Asynchronous method threw an exception: " + ex.Message, ex); }
1312
1313 ar.AsyncWaitHandle.Close();
1314 }
1315 }
1292 1316
1293 public static void FireAndForget(System.Threading.WaitCallback callback) 1317 public static void FireAndForget(System.Threading.WaitCallback callback)
1294 { 1318 {
1295 //FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>(); 1319 FireAndForget(callback, null);
1296 //wrapper.FireAndForget(callback);
1297 System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, null);
1298 } 1320 }
1299 1321
1300 public static void SetMaxThreads(int maxThreads) 1322 public static void SetMaxThreads(int maxThreads)
1301 { 1323 {
1324 if (m_ThreadPool != null)
1325 return;
1326
1302 STPStartInfo startInfo = new STPStartInfo(); 1327 STPStartInfo startInfo = new STPStartInfo();
1303 startInfo.IdleTimeout = 2000; // 2 seconds 1328 startInfo.IdleTimeout = 2000; // 2 seconds
1304 startInfo.MaxWorkerThreads = maxThreads; 1329 startInfo.MaxWorkerThreads = maxThreads;
@@ -1313,11 +1338,28 @@ namespace OpenSim.Framework
1313 1338
1314 public static void FireAndForget(System.Threading.WaitCallback callback, object obj) 1339 public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
1315 { 1340 {
1316 m_ThreadPool.QueueWorkItem(new WorkItemCallback(delegate(object o) 1341 switch (FireAndForgetMethod)
1317 { 1342 {
1318 callback(o); 1343 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
1319 return null; 1344 System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj);
1320 }), obj); 1345 break;
1346 case FireAndForgetMethod.QueueUserWorkItem:
1347 System.Threading.ThreadPool.QueueUserWorkItem(callback, obj);
1348 break;
1349 case FireAndForgetMethod.BeginInvoke:
1350 FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>();
1351 wrapper.FireAndForget(callback, obj);
1352 break;
1353 case FireAndForgetMethod.SmartThreadPool:
1354 m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
1355 break;
1356 case FireAndForgetMethod.Thread:
1357 System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); });
1358 thread.Start(obj);
1359 break;
1360 default:
1361 throw new NotImplementedException();
1362 }
1321 } 1363 }
1322 1364
1323 #endregion FireAndForget Threading Pattern 1365 #endregion FireAndForget Threading Pattern
diff --git a/OpenSim/Grid/MessagingServer.Modules/MessageService.cs b/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
index 49f0fa8..8ad1e9c 100644
--- a/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
+++ b/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
@@ -148,8 +148,7 @@ namespace OpenSim.Grid.MessagingServer.Modules
148 friendlistupdater.presence2 = receiver; 148 friendlistupdater.presence2 = receiver;
149 friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo; 149 friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo;
150 friendlistupdater.OnDone += PresenceUpdateDone; 150 friendlistupdater.OnDone += PresenceUpdateDone;
151 WaitCallback cb = new WaitCallback(friendlistupdater.go); 151 Util.FireAndForget(friendlistupdater.go);
152 ThreadPool.UnsafeQueueUserWorkItem(cb, null);
153 } 152 }
154 else 153 else
155 { 154 {
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index c9cec75..c04b8c2 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -92,10 +92,17 @@ namespace OpenSim
92 appender.File = fileName; 92 appender.File = fileName;
93 appender.ActivateOptions(); 93 appender.ActivateOptions();
94 } 94 }
95 m_log.InfoFormat("[LOGGING] Logging started to file {0}", appender.File); 95 m_log.InfoFormat("[LOGGING]: Logging started to file {0}", appender.File);
96 } 96 }
97 } 97 }
98
99 string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
100 FireAndForgetMethod asyncCallMethod;
101 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
102 Util.FireAndForgetMethod = asyncCallMethod;
98 } 103 }
104
105 m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);
99 } 106 }
100 107
101 /// <summary> 108 /// <summary>
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index 432fee7..0ba76ec 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -791,7 +791,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
791 /// <param name="map">heightmap</param> 791 /// <param name="map">heightmap</param>
792 public virtual void SendLayerData(float[] map) 792 public virtual void SendLayerData(float[] map)
793 { 793 {
794 ThreadPool.UnsafeQueueUserWorkItem(DoSendLayerData, map); 794 Util.FireAndForget(DoSendLayerData, map);
795 } 795 }
796 796
797 /// <summary> 797 /// <summary>
@@ -931,7 +931,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
931 /// <param name="windSpeeds">16x16 array of wind speeds</param> 931 /// <param name="windSpeeds">16x16 array of wind speeds</param>
932 public virtual void SendWindData(Vector2[] windSpeeds) 932 public virtual void SendWindData(Vector2[] windSpeeds)
933 { 933 {
934 ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(DoSendWindData), (object)windSpeeds); 934 Util.FireAndForget(DoSendWindData, windSpeeds);
935 } 935 }
936 936
937 /// <summary> 937 /// <summary>
@@ -940,7 +940,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
940 /// <param name="windSpeeds">16x16 array of cloud densities</param> 940 /// <param name="windSpeeds">16x16 array of cloud densities</param>
941 public virtual void SendCloudData(float[] cloudDensity) 941 public virtual void SendCloudData(float[] cloudDensity)
942 { 942 {
943 ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(DoSendCloudData), (object)cloudDensity); 943 Util.FireAndForget(DoSendCloudData, cloudDensity);
944 } 944 }
945 945
946 /// <summary> 946 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index cbdca16..c6af806 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -302,12 +302,8 @@ namespace Flotsam.RegionModules.AssetCache
302 302
303 } 303 }
304 304
305 ThreadPool.UnsafeQueueUserWorkItem( 305 Util.FireAndForget(
306 delegate 306 delegate { WriteFileCache(filename, asset); });
307 {
308 WriteFileCache(filename, asset);
309 }, null
310 );
311 } 307 }
312 } 308 }
313 catch (Exception e) 309 catch (Exception e)
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index 1260584..4e40084 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -1095,7 +1095,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1095 // The reason is so we don't cause the thread to freeze waiting 1095 // The reason is so we don't cause the thread to freeze waiting
1096 // for the 1 second it costs to start a thread manually. 1096 // for the 1 second it costs to start a thread manually.
1097 if (!threadrunning) 1097 if (!threadrunning)
1098 ThreadPool.UnsafeQueueUserWorkItem(this.StartThread, null); 1098 Util.FireAndForget(this.StartThread);
1099 1099
1100 lock (m_rootAgents) 1100 lock (m_rootAgents)
1101 { 1101 {
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index 25d3f39..79d57d2 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -31,6 +31,15 @@
31 31
32 ; To run a script every few minutes, set the script filename here 32 ; To run a script every few minutes, set the script filename here
33 ; timer_Script = "filename" 33 ; timer_Script = "filename"
34
35 ; ##
36 ; ## SYSTEM
37 ; ##
38
39 ; Sets the method that OpenSim will use to fire asynchronous
40 ; events. Valid values are UnsafeQueueUserWorkItem,
41 ; QueueUserWorkItem, BeginInvoke, SmartThreadPool, and Thread
42 ; async_call_method = SmartThreadPool
34 43
35 ; ## 44 ; ##
36 ; ## CLIENTS 45 ; ## CLIENTS