diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--[-rwxr-xr-x] | OpenSim/Framework/MinHeap.cs | 27 | ||||
-rw-r--r-- | OpenSim/Framework/Util.cs | 30 |
2 files changed, 40 insertions, 17 deletions
diff --git a/OpenSim/Framework/MinHeap.cs b/OpenSim/Framework/MinHeap.cs index ad39bbc..33d0364 100755..100644 --- a/OpenSim/Framework/MinHeap.cs +++ b/OpenSim/Framework/MinHeap.cs | |||
@@ -1,3 +1,30 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
1 | using System; | 28 | using System; |
2 | using System.Threading; | 29 | using System.Threading; |
3 | using System.Collections; | 30 | using System.Collections; |
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index d09bd6d..a18a827 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -69,8 +69,6 @@ namespace OpenSim.Framework | |||
69 | /// </summary> | 69 | /// </summary> |
70 | public class Util | 70 | public class Util |
71 | { | 71 | { |
72 | private static SmartThreadPool m_ThreadPool = null; | ||
73 | |||
74 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 72 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
75 | 73 | ||
76 | private static uint nextXferID = 5000; | 74 | private static uint nextXferID = 5000; |
@@ -79,6 +77,9 @@ namespace OpenSim.Framework | |||
79 | private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]"; | 77 | private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]"; |
80 | private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; | 78 | private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; |
81 | private static object XferLock = new object(); | 79 | private static object XferLock = new object(); |
80 | /// <summary>Thread pool used for Util.FireAndForget if | ||
81 | /// FireAndForgetMethod.SmartThreadPool is used</summary> | ||
82 | private static SmartThreadPool m_ThreadPool; | ||
82 | 83 | ||
83 | // Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC. | 84 | // Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC. |
84 | private static readonly DateTime unixEpoch = | 85 | private static readonly DateTime unixEpoch = |
@@ -1319,21 +1320,14 @@ namespace OpenSim.Framework | |||
1319 | FireAndForget(callback, null); | 1320 | FireAndForget(callback, null); |
1320 | } | 1321 | } |
1321 | 1322 | ||
1322 | public static void SetMaxThreads(int maxThreads) | 1323 | public static void InitThreadPool(int maxThreads) |
1323 | { | 1324 | { |
1325 | if (maxThreads < 2) | ||
1326 | throw new ArgumentOutOfRangeException("maxThreads", "maxThreads must be greater than 2"); | ||
1324 | if (m_ThreadPool != null) | 1327 | if (m_ThreadPool != null) |
1325 | return; | 1328 | throw new InvalidOperationException("SmartThreadPool is already initialized"); |
1326 | |||
1327 | STPStartInfo startInfo = new STPStartInfo(); | ||
1328 | startInfo.IdleTimeout = 2000; // 2 seconds | ||
1329 | startInfo.MaxWorkerThreads = maxThreads; | ||
1330 | startInfo.MinWorkerThreads = 2; | ||
1331 | startInfo.StackSize = 524288; | ||
1332 | startInfo.ThreadPriority = ThreadPriority.Normal; | ||
1333 | |||
1334 | startInfo.StartSuspended = false; | ||
1335 | 1329 | ||
1336 | m_ThreadPool = new SmartThreadPool(startInfo); | 1330 | m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); |
1337 | } | 1331 | } |
1338 | 1332 | ||
1339 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) | 1333 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) |
@@ -1341,20 +1335,22 @@ namespace OpenSim.Framework | |||
1341 | switch (FireAndForgetMethod) | 1335 | switch (FireAndForgetMethod) |
1342 | { | 1336 | { |
1343 | case FireAndForgetMethod.UnsafeQueueUserWorkItem: | 1337 | case FireAndForgetMethod.UnsafeQueueUserWorkItem: |
1344 | System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj); | 1338 | ThreadPool.UnsafeQueueUserWorkItem(callback, obj); |
1345 | break; | 1339 | break; |
1346 | case FireAndForgetMethod.QueueUserWorkItem: | 1340 | case FireAndForgetMethod.QueueUserWorkItem: |
1347 | System.Threading.ThreadPool.QueueUserWorkItem(callback, obj); | 1341 | ThreadPool.QueueUserWorkItem(callback, obj); |
1348 | break; | 1342 | break; |
1349 | case FireAndForgetMethod.BeginInvoke: | 1343 | case FireAndForgetMethod.BeginInvoke: |
1350 | FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>(); | 1344 | FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>(); |
1351 | wrapper.FireAndForget(callback, obj); | 1345 | wrapper.FireAndForget(callback, obj); |
1352 | break; | 1346 | break; |
1353 | case FireAndForgetMethod.SmartThreadPool: | 1347 | case FireAndForgetMethod.SmartThreadPool: |
1348 | if (m_ThreadPool != null) | ||
1349 | m_ThreadPool = new SmartThreadPool(2000, 15, 2); | ||
1354 | m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj); | 1350 | m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj); |
1355 | break; | 1351 | break; |
1356 | case FireAndForgetMethod.Thread: | 1352 | case FireAndForgetMethod.Thread: |
1357 | System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); }); | 1353 | Thread thread = new Thread(delegate(object o) { callback(o); }); |
1358 | thread.Start(obj); | 1354 | thread.Start(obj); |
1359 | break; | 1355 | break; |
1360 | default: | 1356 | default: |