diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 893f3ef60a..f9af9c1c03 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 bb08d90483..5ee8dbfad2 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); }