aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rwxr-xr-xOpenSim/Region/ScriptEngine/XEngine/XEngine.cs381
1 files changed, 281 insertions, 100 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 78d4ee9..466c190 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; //for [DebuggerNonUserCode]
31using System.Globalization; 32using System.Globalization;
32using System.IO; 33using System.IO;
33using System.Linq; 34using System.Linq;
@@ -161,6 +162,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
161 private Dictionary<UUID, IScriptInstance> m_Scripts = 162 private Dictionary<UUID, IScriptInstance> m_Scripts =
162 new Dictionary<UUID, IScriptInstance>(); 163 new Dictionary<UUID, IScriptInstance>();
163 164
165 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
166
164 // Maps the asset ID to the assembly 167 // Maps the asset ID to the assembly
165 168
166 private Dictionary<UUID, string> m_Assemblies = 169 private Dictionary<UUID, string> m_Assemblies =
@@ -183,6 +186,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
183 IWorkItemResult m_CurrentCompile = null; 186 IWorkItemResult m_CurrentCompile = null;
184 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 187 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
185 188
189 private void lockScriptsForRead(bool locked)
190 {
191 if (locked)
192 {
193 if (m_scriptsLock.RecursiveReadCount > 0)
194 {
195 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
196 m_scriptsLock.ExitReadLock();
197 }
198 if (m_scriptsLock.RecursiveWriteCount > 0)
199 {
200 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
201 m_scriptsLock.ExitWriteLock();
202 }
203
204 while (!m_scriptsLock.TryEnterReadLock(60000))
205 {
206 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
207 if (m_scriptsLock.IsWriteLockHeld)
208 {
209 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
210 }
211 }
212 }
213 else
214 {
215 if (m_scriptsLock.RecursiveReadCount > 0)
216 {
217 m_scriptsLock.ExitReadLock();
218 }
219 }
220 }
221 private void lockScriptsForWrite(bool locked)
222 {
223 if (locked)
224 {
225 if (m_scriptsLock.RecursiveReadCount > 0)
226 {
227 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
228 m_scriptsLock.ExitReadLock();
229 }
230 if (m_scriptsLock.RecursiveWriteCount > 0)
231 {
232 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
233 m_scriptsLock.ExitWriteLock();
234 }
235
236 while (!m_scriptsLock.TryEnterWriteLock(60000))
237 {
238 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
239 if (m_scriptsLock.IsWriteLockHeld)
240 {
241 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
242 }
243 }
244 }
245 else
246 {
247 if (m_scriptsLock.RecursiveWriteCount > 0)
248 {
249 m_scriptsLock.ExitWriteLock();
250 }
251 }
252 }
253
186 private ScriptEngineConsoleCommands m_consoleCommands; 254 private ScriptEngineConsoleCommands m_consoleCommands;
187 255
188 public string ScriptEngineName 256 public string ScriptEngineName
@@ -714,20 +782,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine
714 { 782 {
715 if (!m_Enabled) 783 if (!m_Enabled)
716 return; 784 return;
785 lockScriptsForRead(true);
717 786
718 lock (m_Scripts) 787 List<IScriptInstance> instancesToDel = new List<IScriptInstance>(m_Scripts.Values);
719 {
720 m_log.InfoFormat(
721 "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName);
722 788
723 foreach (IScriptInstance instance in m_Scripts.Values) 789// foreach (IScriptInstance instance in m_Scripts.Values)
790 foreach (IScriptInstance instance in instancesToDel)
791 {
792 // Force a final state save
793 //
794 if (m_Assemblies.ContainsKey(instance.AssetID))
724 { 795 {
796<<<<<<< HEAD
725 // Force a final state save 797 // Force a final state save
726 // 798 //
727 try 799 try
728 { 800 {
729 if (instance.StatePersistedHere) 801 if (instance.StatePersistedHere)
730 instance.SaveState(); 802 instance.SaveState();
803=======
804 string assembly = m_Assemblies[instance.AssetID];
805
806 try
807 {
808 instance.SaveState(assembly);
809>>>>>>> avn/ubitvar
731 } 810 }
732 catch (Exception e) 811 catch (Exception e)
733 { 812 {
@@ -737,36 +816,50 @@ namespace OpenSim.Region.ScriptEngine.XEngine
737 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name) 816 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
738 , e); 817 , e);
739 } 818 }
819 }
740 820
821<<<<<<< HEAD
741 // Clear the event queue and abort the instance thread 822 // Clear the event queue and abort the instance thread
742 // 823 //
743 instance.Stop(0, true); 824 instance.Stop(0, true);
825=======
826 // Clear the event queue and abort the instance thread
827 //
828 instance.ClearQueue();
829 instance.Stop(0);
830>>>>>>> avn/ubitvar
744 831
745 // Release events, timer, etc 832 // Release events, timer, etc
746 // 833 //
747 instance.DestroyScriptInstance(); 834 instance.DestroyScriptInstance();
748 835
749 // Unload scripts and app domains. 836 // Unload scripts and app domains
750 // Must be done explicitly because they have infinite 837 // Must be done explicitly because they have infinite
751 // lifetime. 838 // lifetime
752 // However, don't bother to do this if the simulator is shutting 839 //
753 // down since it takes a long time with many scripts. 840// if (!m_SimulatorShuttingDown)
754 if (!m_SimulatorShuttingDown) 841 {
842 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
843 if (m_DomainScripts[instance.AppDomain].Count == 0)
755 { 844 {
756 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 845 m_DomainScripts.Remove(instance.AppDomain);
757 if (m_DomainScripts[instance.AppDomain].Count == 0) 846 UnloadAppDomain(instance.AppDomain);
758 {
759 m_DomainScripts.Remove(instance.AppDomain);
760 UnloadAppDomain(instance.AppDomain);
761 }
762 } 847 }
763 } 848 }
764 849
765 m_Scripts.Clear(); 850// m_Scripts.Clear();
766 m_PrimObjects.Clear(); 851// m_PrimObjects.Clear();
767 m_Assemblies.Clear(); 852// m_Assemblies.Clear();
768 m_DomainScripts.Clear(); 853// m_DomainScripts.Clear();
769 } 854 }
855 lockScriptsForRead(false);
856 lockScriptsForWrite(true);
857 m_Scripts.Clear();
858 lockScriptsForWrite(false);
859 m_PrimObjects.Clear();
860 m_Assemblies.Clear();
861 m_DomainScripts.Clear();
862
770 lock (m_ScriptEngines) 863 lock (m_ScriptEngines)
771 { 864 {
772 m_ScriptEngines.Remove(this); 865 m_ScriptEngines.Remove(this);
@@ -835,6 +928,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
835 928
836 List<IScriptInstance> instances = new List<IScriptInstance>(); 929 List<IScriptInstance> instances = new List<IScriptInstance>();
837 930
931<<<<<<< HEAD
838 lock (m_Scripts) 932 lock (m_Scripts)
839 { 933 {
840 foreach (IScriptInstance instance in m_Scripts.Values) 934 foreach (IScriptInstance instance in m_Scripts.Values)
@@ -852,6 +946,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
852 946
853 foreach (IScriptInstance i in instances) 947 foreach (IScriptInstance i in instances)
854 { 948 {
949=======
950 lockScriptsForRead(true);
951 foreach (IScriptInstance instance in m_Scripts.Values)
952 instances.Add(instance);
953 lockScriptsForRead(false);
954
955 foreach (IScriptInstance i in instances)
956 {
957 string assembly = String.Empty;
958
959
960 if (!m_Assemblies.ContainsKey(i.AssetID))
961 continue;
962 assembly = m_Assemblies[i.AssetID];
963
964
965>>>>>>> avn/ubitvar
855 try 966 try
856 { 967 {
857 i.SaveState(); 968 i.SaveState();
@@ -1282,58 +1393,79 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1282 } 1393 }
1283 1394
1284 ScriptInstance instance = null; 1395 ScriptInstance instance = null;
1285 lock (m_Scripts) 1396 // Create the object record
1397 UUID appDomain = assetID;
1398
1399
1400
1401 lockScriptsForRead(true);
1402 if ((!m_Scripts.ContainsKey(itemID)) ||
1403 (m_Scripts[itemID].AssetID != assetID))
1286 { 1404 {
1287 // Create the object record 1405 lockScriptsForRead(false);
1288 if ((!m_Scripts.ContainsKey(itemID)) || 1406 instance = new ScriptInstance(this, part,
1289 (m_Scripts[itemID].AssetID != assetID)) 1407 item,
1290 { 1408 startParam, postOnRez,
1291 UUID appDomain = assetID; 1409 m_MaxScriptQueue);
1292 1410
1293 if (part.ParentGroup.IsAttachment) 1411 if (part.ParentGroup.IsAttachment)
1294 appDomain = part.ParentGroup.RootPart.UUID; 1412 appDomain = part.ParentGroup.RootPart.UUID;
1295 1413
1296 if (!m_AppDomains.ContainsKey(appDomain)) 1414 if (!m_AppDomains.ContainsKey(appDomain))
1415 {
1416 try
1297 { 1417 {
1298 try 1418 AppDomainSetup appSetup = new AppDomainSetup();
1299 { 1419 appSetup.PrivateBinPath = Path.Combine(
1300 AppDomainSetup appSetup = new AppDomainSetup(); 1420 m_ScriptEnginesPath,
1301 appSetup.PrivateBinPath = Path.Combine( 1421 m_Scene.RegionInfo.RegionID.ToString());
1302 m_ScriptEnginesPath,
1303 m_Scene.RegionInfo.RegionID.ToString());
1304 1422
1305 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 1423 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
1306 Evidence evidence = new Evidence(baseEvidence); 1424 Evidence evidence = new Evidence(baseEvidence);
1307 1425
1308 AppDomain sandbox; 1426 AppDomain sandbox;
1309 if (m_AppDomainLoading) 1427 if (m_AppDomainLoading)
1428 {
1429 sandbox = AppDomain.CreateDomain(
1430 m_Scene.RegionInfo.RegionID.ToString(),
1431 evidence, appSetup);
1432 if (m_AppDomains.ContainsKey(appDomain))
1310 { 1433 {
1311 sandbox = AppDomain.CreateDomain( 1434 m_AppDomains[appDomain].AssemblyResolve +=
1312 m_Scene.RegionInfo.RegionID.ToString(),
1313 evidence, appSetup);
1314 sandbox.AssemblyResolve +=
1315 new ResolveEventHandler( 1435 new ResolveEventHandler(
1316 AssemblyResolver.OnAssemblyResolve); 1436 AssemblyResolver.OnAssemblyResolve);
1437 if (m_DomainScripts.ContainsKey(appDomain))
1438 {
1439 m_DomainScripts[appDomain].Add(itemID);
1440 }
1441 else
1442 {
1443 m_DomainScripts.Add(appDomain, new List<UUID>());
1444 m_DomainScripts[appDomain].Add(itemID);
1445 }
1317 } 1446 }
1318 else 1447 else
1319 { 1448 {
1320 sandbox = AppDomain.CurrentDomain; 1449 m_AppDomains.Add(appDomain, sandbox);
1450 m_AppDomains[appDomain].AssemblyResolve +=
1451 new ResolveEventHandler(
1452 AssemblyResolver.OnAssemblyResolve);
1453 if (m_DomainScripts.ContainsKey(appDomain))
1454 {
1455 m_DomainScripts[appDomain].Add(itemID);
1456 }
1457 else
1458 {
1459 m_DomainScripts.Add(appDomain, new List<UUID>());
1460 m_DomainScripts[appDomain].Add(itemID);
1461 }
1462
1321 } 1463 }
1322
1323 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1324 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
1325 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
1326 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
1327 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
1328 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
1329 //sandbox.SetAppDomainPolicy(sandboxPolicy);
1330
1331 m_AppDomains[appDomain] = sandbox;
1332 1464
1333 m_DomainScripts[appDomain] = new List<UUID>();
1334 } 1465 }
1335 catch (Exception e) 1466 else
1336 { 1467 {
1468<<<<<<< HEAD
1337 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 1469 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
1338 m_ScriptErrorMessage += "Exception creating app domain:\n"; 1470 m_ScriptErrorMessage += "Exception creating app domain:\n";
1339 m_ScriptFailCount++; 1471 m_ScriptFailCount++;
@@ -1342,10 +1474,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1342 m_AddingAssemblies[assemblyPath]--; 1474 m_AddingAssemblies[assemblyPath]--;
1343 } 1475 }
1344 return false; 1476 return false;
1477=======
1478 sandbox = AppDomain.CurrentDomain;
1479>>>>>>> avn/ubitvar
1345 } 1480 }
1346 }
1347 m_DomainScripts[appDomain].Add(itemID);
1348 1481
1482<<<<<<< HEAD
1349 IScript scriptObj = null; 1483 IScript scriptObj = null;
1350 EventWaitHandle coopSleepHandle; 1484 EventWaitHandle coopSleepHandle;
1351 bool coopTerminationForThisScript; 1485 bool coopTerminationForThisScript;
@@ -1477,26 +1611,52 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1477 scriptObj, coopSleepHandle, assemblyPath, 1611 scriptObj, coopSleepHandle, assemblyPath,
1478 Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript)) 1612 Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript))
1479 return false; 1613 return false;
1614=======
1615// if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource))
1616// return false;
1617>>>>>>> avn/ubitvar
1480 1618
1481// if (DebugLevel >= 1) 1619 m_AppDomains[appDomain] = sandbox;
1482// m_log.DebugFormat(
1483// "[XEngine] Loaded script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}",
1484// part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID,
1485// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1486 1620
1487 if (presence != null) 1621 m_DomainScripts[appDomain] = new List<UUID>();
1622 }
1623 catch (Exception e)
1488 { 1624 {
1489 ShowScriptSaveResponse(item.OwnerID, 1625 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
1490 assetID, "Compile successful", true); 1626 m_ScriptErrorMessage += "Exception creating app domain:\n";
1627 m_ScriptFailCount++;
1628 lock (m_AddingAssemblies)
1629 {
1630 m_AddingAssemblies[assembly]--;
1631 }
1632 return false;
1491 } 1633 }
1634 }
1492 1635
1493 instance.AppDomain = appDomain;
1494 instance.LineMap = linemap;
1495 1636
1496 m_Scripts[itemID] = instance; 1637 if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource))
1638 return false;
1639// m_log.DebugFormat(
1640// "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
1641// part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
1642// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1643
1644 if (presence != null)
1645 {
1646 ShowScriptSaveResponse(item.OwnerID,
1647 assetID, "Compile successful", true);
1497 } 1648 }
1498 }
1499 1649
1650 instance.AppDomain = appDomain;
1651 instance.LineMap = linemap;
1652 lockScriptsForWrite(true);
1653 m_Scripts[itemID] = instance;
1654 lockScriptsForWrite(false);
1655 }
1656 else
1657 {
1658 lockScriptsForRead(false);
1659 }
1500 lock (m_PrimObjects) 1660 lock (m_PrimObjects)
1501 { 1661 {
1502 if (!m_PrimObjects.ContainsKey(localID)) 1662 if (!m_PrimObjects.ContainsKey(localID))
@@ -1514,7 +1674,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1514 m_AddingAssemblies[assemblyPath]--; 1674 m_AddingAssemblies[assemblyPath]--;
1515 } 1675 }
1516 1676
1517 if (instance != null) 1677 if (instance!=null)
1518 instance.Init(); 1678 instance.Init();
1519 1679
1520 bool runIt; 1680 bool runIt;
@@ -1537,19 +1697,28 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1537 m_CompileDict.Remove(itemID); 1697 m_CompileDict.Remove(itemID);
1538 } 1698 }
1539 1699
1540 IScriptInstance instance = null; 1700 lockScriptsForRead(true);
1541 1701 // Do we even have it?
1542 lock (m_Scripts) 1702 if (!m_Scripts.ContainsKey(itemID))
1543 { 1703 {
1544 // Do we even have it? 1704 lockScriptsForRead(false);
1545 if (!m_Scripts.ContainsKey(itemID)) 1705 return;
1546 return; 1706 }
1547
1548 instance = m_Scripts[itemID];
1549 m_Scripts.Remove(itemID);
1550 }
1551 1707
1708<<<<<<< HEAD
1552 instance.Stop(m_WaitForEventCompletionOnScriptStop, true); 1709 instance.Stop(m_WaitForEventCompletionOnScriptStop, true);
1710=======
1711 IScriptInstance instance=m_Scripts[itemID];
1712 lockScriptsForRead(false);
1713 lockScriptsForWrite(true);
1714 m_Scripts.Remove(itemID);
1715 lockScriptsForWrite(false);
1716 instance.ClearQueue();
1717
1718 instance.Stop(m_WaitForEventCompletionOnScriptStop);
1719
1720// bool objectRemoved = false;
1721>>>>>>> avn/ubitvar
1553 1722
1554 lock (m_PrimObjects) 1723 lock (m_PrimObjects)
1555 { 1724 {
@@ -1571,17 +1740,26 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1571 1740
1572 instance.DestroyScriptInstance(); 1741 instance.DestroyScriptInstance();
1573 1742
1574 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 1743 if (m_DomainScripts.ContainsKey(instance.AppDomain))
1575 if (m_DomainScripts[instance.AppDomain].Count == 0)
1576 { 1744 {
1577 m_DomainScripts.Remove(instance.AppDomain); 1745 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
1578 UnloadAppDomain(instance.AppDomain); 1746 if (m_DomainScripts[instance.AppDomain].Count == 0)
1747 {
1748 m_DomainScripts.Remove(instance.AppDomain);
1749 UnloadAppDomain(instance.AppDomain);
1750 }
1579 } 1751 }
1580 1752
1581 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 1753 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
1582 if (handlerObjectRemoved != null) 1754 if (handlerObjectRemoved != null)
1583 handlerObjectRemoved(instance.ObjectID); 1755 {
1756 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
1757 if (part != null)
1758 handlerObjectRemoved(part.UUID);
1759 }
1584 1760
1761 CleanAssemblies();
1762
1585 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 1763 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
1586 if (handlerScriptRemoved != null) 1764 if (handlerScriptRemoved != null)
1587 handlerScriptRemoved(itemID); 1765 handlerScriptRemoved(itemID);
@@ -1842,12 +2020,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1842 private IScriptInstance GetInstance(UUID itemID) 2020 private IScriptInstance GetInstance(UUID itemID)
1843 { 2021 {
1844 IScriptInstance instance; 2022 IScriptInstance instance;
1845 lock (m_Scripts) 2023 lockScriptsForRead(true);
2024 if (!m_Scripts.ContainsKey(itemID))
1846 { 2025 {
1847 if (!m_Scripts.ContainsKey(itemID)) 2026 lockScriptsForRead(false);
1848 return null; 2027 return null;
1849 instance = m_Scripts[itemID];
1850 } 2028 }
2029 instance = m_Scripts[itemID];
2030 lockScriptsForRead(false);
1851 return instance; 2031 return instance;
1852 } 2032 }
1853 2033
@@ -1869,6 +2049,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1869 return instance != null && instance.Running; 2049 return instance != null && instance.Running;
1870 } 2050 }
1871 2051
2052 [DebuggerNonUserCode]
1872 public void ApiResetScript(UUID itemID) 2053 public void ApiResetScript(UUID itemID)
1873 { 2054 {
1874 IScriptInstance instance = GetInstance(itemID); 2055 IScriptInstance instance = GetInstance(itemID);
@@ -1953,6 +2134,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1953 return instance != null ? instance.GetDetectID(idx) : UUID.Zero; 2134 return instance != null ? instance.GetDetectID(idx) : UUID.Zero;
1954 } 2135 }
1955 2136
2137 [DebuggerNonUserCode]
1956 public void SetState(UUID itemID, string newState) 2138 public void SetState(UUID itemID, string newState)
1957 { 2139 {
1958 IScriptInstance instance = GetInstance(itemID); 2140 IScriptInstance instance = GetInstance(itemID);
@@ -1973,11 +2155,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1973 2155
1974 List<IScriptInstance> instances = new List<IScriptInstance>(); 2156 List<IScriptInstance> instances = new List<IScriptInstance>();
1975 2157
1976 lock (m_Scripts) 2158 lockScriptsForRead(true);
1977 { 2159 foreach (IScriptInstance instance in m_Scripts.Values)
1978 foreach (IScriptInstance instance in m_Scripts.Values)
1979 instances.Add(instance); 2160 instances.Add(instance);
1980 } 2161 lockScriptsForRead(false);
1981 2162
1982 foreach (IScriptInstance i in instances) 2163 foreach (IScriptInstance i in instances)
1983 { 2164 {