From 5607fd3af828846291de3358067bb1214619489e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 19 Oct 2011 21:30:37 +0100 Subject: Fix resume scripts. On resume, we need to place requeue the script for event processing if there are any events on the queue. Also need to do this under m_Script lock in order to avoid a race --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 40 +++++++++++++++++----- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 2 +- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 893f3ef..f9af9c1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -55,7 +55,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { public class ScriptInstance : MarshalByRefObject, IScriptInstance { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IScriptEngine m_Engine; private IScriptWorkItem m_CurrentResult = null; @@ -138,7 +138,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance set { m_RunEvents = value; } } - public bool Suspended { get; set; } + public bool Suspended + { + get { return m_Suspended; } + + set + { + // Need to do this inside a lock in order to avoid races with EventProcessor() + lock (m_Script) + { + bool wasSuspended = m_Suspended; + m_Suspended = value; + + if (wasSuspended && !m_Suspended) + { + lock (m_EventQueue) + { + // Need to place ourselves back in a work item if there are events to process + if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) + m_CurrentResult = m_Engine.QueueEventHandler(this); + } + } + } + } + } + private bool m_Suspended; public bool ShuttingDown { @@ -645,13 +669,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance /// public object EventProcessor() { -// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); - - if (Suspended) - return 0; - lock (m_Script) { +// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); + + if (Suspended) + return 0; + EventParams data = null; lock (m_EventQueue) @@ -689,7 +713,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", // m_PrimName, m_ScriptName, data.Params[0].ToString()); - m_State=data.Params[0].ToString(); + m_State = data.Params[0].ToString(); AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index bb08d90..5ee8dbf 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -946,7 +946,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (!m_Scripts.ContainsKey(itemID)) return; - instance=m_Scripts[itemID]; + instance = m_Scripts[itemID]; m_Scripts.Remove(itemID); } -- cgit v1.1