aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-07-14 20:08:11 +0100
committerJustin Clark-Casey (justincc)2014-07-14 20:08:11 +0100
commit0c8f3dddd89bb1578797ada8f23bc1ed07d1afff (patch)
tree9d83eb751d451ef0df83c0e424687e4cf99c2e64 /OpenSim/Region
parentminor: Remove compiler warning in GridService (diff)
downloadopensim-SC_OLD-0c8f3dddd89bb1578797ada8f23bc1ed07d1afff.zip
opensim-SC_OLD-0c8f3dddd89bb1578797ada8f23bc1ed07d1afff.tar.gz
opensim-SC_OLD-0c8f3dddd89bb1578797ada8f23bc1ed07d1afff.tar.bz2
opensim-SC_OLD-0c8f3dddd89bb1578797ada8f23bc1ed07d1afff.tar.xz
Use thread-safe version of .NET Random as the SDK class is not thread-safe.
As per http://msdn.microsoft.com/en-us/library/system.random%28v=vs.100%29.aspx, the .NET Random class is not thread-safe. If called by multiple threads at once, methods may return 0. Except for llRand(), other OpenSimulator code did not lock before calling a shared Random instance. This commit adds a ThreadSafeRandom class that extends Random but does internal locking so that it is thread-safe. This change is invisible to existing callers and the explicit locking in the llFrand() implementation is now redundant.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs6
1 files changed, 2 insertions, 4 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 7d8821c..991107e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -544,10 +544,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
544 public LSL_Float llFrand(double mag) 544 public LSL_Float llFrand(double mag)
545 { 545 {
546 m_host.AddScriptLPS(1); 546 m_host.AddScriptLPS(1);
547 lock (Util.RandomClass) 547
548 { 548 return Util.RandomClass.NextDouble() * mag;
549 return Util.RandomClass.NextDouble() * mag;
550 }
551 } 549 }
552 550
553 public LSL_Integer llFloor(double f) 551 public LSL_Integer llFloor(double f)