diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index b8b1039..2d58807 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -56,8 +56,13 @@ namespace OpenSim.Framework | |||
56 | /// <summary> | 56 | /// <summary> |
57 | /// The method used by Util.FireAndForget for asynchronously firing events | 57 | /// The method used by Util.FireAndForget for asynchronously firing events |
58 | /// </summary> | 58 | /// </summary> |
59 | /// <remarks> | ||
60 | /// None is used to execute the method in the same thread that made the call. It should only be used by regression | ||
61 | /// test code that relies on predictable event ordering. | ||
62 | /// </remarks> | ||
59 | public enum FireAndForgetMethod | 63 | public enum FireAndForgetMethod |
60 | { | 64 | { |
65 | None, | ||
61 | UnsafeQueueUserWorkItem, | 66 | UnsafeQueueUserWorkItem, |
62 | QueueUserWorkItem, | 67 | QueueUserWorkItem, |
63 | BeginInvoke, | 68 | BeginInvoke, |
@@ -89,7 +94,8 @@ namespace OpenSim.Framework | |||
89 | public static readonly Regex UUIDPattern | 94 | public static readonly Regex UUIDPattern |
90 | = 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}$"); | 95 | = 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}$"); |
91 | 96 | ||
92 | public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.SmartThreadPool; | 97 | public static FireAndForgetMethod DefaultFireAndForgetMethod = FireAndForgetMethod.SmartThreadPool; |
98 | public static FireAndForgetMethod FireAndForgetMethod = DefaultFireAndForgetMethod; | ||
93 | 99 | ||
94 | /// <summary> | 100 | /// <summary> |
95 | /// Gets the name of the directory where the current running executable | 101 | /// Gets the name of the directory where the current running executable |
@@ -1511,25 +1517,47 @@ namespace OpenSim.Framework | |||
1511 | 1517 | ||
1512 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) | 1518 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) |
1513 | { | 1519 | { |
1520 | // When OpenSim interacts with a database or sends data over the wire, it must send this in en_US culture | ||
1521 | // so that we don't encounter problems where, for instance, data is saved with a culture that uses commas | ||
1522 | // for decimals places but is read by a culture that treats commas as number seperators. | ||
1523 | WaitCallback realCallback = delegate(object o) | ||
1524 | { | ||
1525 | Culture.SetCurrentCulture(); | ||
1526 | |||
1527 | try | ||
1528 | { | ||
1529 | callback(o); | ||
1530 | } | ||
1531 | catch (Exception e) | ||
1532 | { | ||
1533 | m_log.ErrorFormat( | ||
1534 | "[UTIL]: Continuing after async_call_method thread terminated with exception {0}{1}", | ||
1535 | e.Message, e.StackTrace); | ||
1536 | } | ||
1537 | }; | ||
1538 | |||
1514 | switch (FireAndForgetMethod) | 1539 | switch (FireAndForgetMethod) |
1515 | { | 1540 | { |
1541 | case FireAndForgetMethod.None: | ||
1542 | realCallback.Invoke(obj); | ||
1543 | break; | ||
1516 | case FireAndForgetMethod.UnsafeQueueUserWorkItem: | 1544 | case FireAndForgetMethod.UnsafeQueueUserWorkItem: |
1517 | ThreadPool.UnsafeQueueUserWorkItem(callback, obj); | 1545 | ThreadPool.UnsafeQueueUserWorkItem(realCallback, obj); |
1518 | break; | 1546 | break; |
1519 | case FireAndForgetMethod.QueueUserWorkItem: | 1547 | case FireAndForgetMethod.QueueUserWorkItem: |
1520 | ThreadPool.QueueUserWorkItem(callback, obj); | 1548 | ThreadPool.QueueUserWorkItem(realCallback, obj); |
1521 | break; | 1549 | break; |
1522 | case FireAndForgetMethod.BeginInvoke: | 1550 | case FireAndForgetMethod.BeginInvoke: |
1523 | FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance; | 1551 | FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance; |
1524 | wrapper.FireAndForget(callback, obj); | 1552 | wrapper.FireAndForget(realCallback, obj); |
1525 | break; | 1553 | break; |
1526 | case FireAndForgetMethod.SmartThreadPool: | 1554 | case FireAndForgetMethod.SmartThreadPool: |
1527 | if (m_ThreadPool == null) | 1555 | if (m_ThreadPool == null) |
1528 | m_ThreadPool = new SmartThreadPool(2000, 15, 2); | 1556 | m_ThreadPool = new SmartThreadPool(2000, 15, 2); |
1529 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { callback, obj }); | 1557 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); |
1530 | break; | 1558 | break; |
1531 | case FireAndForgetMethod.Thread: | 1559 | case FireAndForgetMethod.Thread: |
1532 | Thread thread = new Thread(delegate(object o) { callback(o); }); | 1560 | Thread thread = new Thread(delegate(object o) { realCallback(o); }); |
1533 | thread.Start(obj); | 1561 | thread.Start(obj); |
1534 | break; | 1562 | break; |
1535 | default: | 1563 | default: |