diff options
author | CasperW | 2009-11-23 20:25:53 +0100 |
---|---|---|
committer | CasperW | 2009-11-23 20:25:53 +0100 |
commit | 247c66b3fe792692468ede6a516d85c6c9852d23 (patch) | |
tree | 8779f401224313320b2cad370b16892aef8276c2 /OpenSim/Region | |
parent | Fixed nullrefs (diff) | |
download | opensim-SC-247c66b3fe792692468ede6a516d85c6c9852d23.zip opensim-SC-247c66b3fe792692468ede6a516d85c6c9852d23.tar.gz opensim-SC-247c66b3fe792692468ede6a516d85c6c9852d23.tar.bz2 opensim-SC-247c66b3fe792692468ede6a516d85c6c9852d23.tar.xz |
Swap the locking of m_EventQueue and m_Script to ease locks on script inventory operations
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 234 |
1 files changed, 119 insertions, 115 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index ed3fdbe..063d50f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -640,154 +640,158 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
640 | /// <returns></returns> | 640 | /// <returns></returns> |
641 | public object EventProcessor() | 641 | public object EventProcessor() |
642 | { | 642 | { |
643 | |||
644 | EventParams data = null; | ||
645 | |||
646 | lock (m_EventQueue) | ||
647 | { | ||
643 | lock (m_Script) | 648 | lock (m_Script) |
644 | { | 649 | { |
645 | EventParams data = null; | 650 | data = (EventParams) m_EventQueue.Dequeue(); |
646 | 651 | if (data == null) // Shouldn't happen | |
647 | lock (m_EventQueue) | ||
648 | { | 652 | { |
649 | data = (EventParams) m_EventQueue.Dequeue(); | 653 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) |
650 | if (data == null) // Shouldn't happen | ||
651 | { | 654 | { |
652 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) | 655 | m_CurrentResult = m_Engine.QueueEventHandler(this); |
653 | { | ||
654 | m_CurrentResult = m_Engine.QueueEventHandler(this); | ||
655 | } | ||
656 | else | ||
657 | { | ||
658 | m_CurrentResult = null; | ||
659 | } | ||
660 | return 0; | ||
661 | } | 656 | } |
662 | 657 | else | |
663 | if (data.EventName == "timer") | ||
664 | m_TimerQueued = false; | ||
665 | if (data.EventName == "control") | ||
666 | { | 658 | { |
667 | if (m_ControlEventsInQueue > 0) | 659 | m_CurrentResult = null; |
668 | m_ControlEventsInQueue--; | ||
669 | } | 660 | } |
670 | if (data.EventName == "collision") | 661 | return 0; |
671 | m_CollisionInQueue = false; | ||
672 | } | 662 | } |
673 | |||
674 | //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this); | ||
675 | 663 | ||
676 | m_DetectParams = data.DetectParams; | 664 | if (data.EventName == "timer") |
677 | 665 | m_TimerQueued = false; | |
678 | if (data.EventName == "state") // Hardcoded state change | 666 | if (data.EventName == "control") |
679 | { | 667 | { |
680 | // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", | 668 | if (m_ControlEventsInQueue > 0) |
681 | // m_PrimName, m_ScriptName, data.Params[0].ToString()); | 669 | m_ControlEventsInQueue--; |
682 | m_State=data.Params[0].ToString(); | 670 | } |
683 | AsyncCommandManager.RemoveScript(m_Engine, | 671 | if (data.EventName == "collision") |
684 | m_LocalID, m_ItemID); | 672 | m_CollisionInQueue = false; |
673 | } | ||
674 | } | ||
675 | lock(m_Script) | ||
676 | { | ||
677 | |||
678 | //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this); | ||
685 | 679 | ||
686 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( | 680 | m_DetectParams = data.DetectParams; |
687 | m_LocalID); | 681 | |
688 | if (part != null) | 682 | if (data.EventName == "state") // Hardcoded state change |
689 | { | 683 | { |
690 | part.SetScriptEvents(m_ItemID, | 684 | // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", |
691 | (int)m_Script.GetStateEventFlags(State)); | 685 | // m_PrimName, m_ScriptName, data.Params[0].ToString()); |
692 | } | 686 | m_State=data.Params[0].ToString(); |
687 | AsyncCommandManager.RemoveScript(m_Engine, | ||
688 | m_LocalID, m_ItemID); | ||
689 | |||
690 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( | ||
691 | m_LocalID); | ||
692 | if (part != null) | ||
693 | { | ||
694 | part.SetScriptEvents(m_ItemID, | ||
695 | (int)m_Script.GetStateEventFlags(State)); | ||
693 | } | 696 | } |
694 | else | 697 | } |
698 | else | ||
699 | { | ||
700 | if (m_Engine.World.PipeEventsForScript(m_LocalID) || | ||
701 | data.EventName == "control") // Don't freeze avies! | ||
695 | { | 702 | { |
696 | if (m_Engine.World.PipeEventsForScript(m_LocalID) || | 703 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( |
697 | data.EventName == "control") // Don't freeze avies! | 704 | m_LocalID); |
698 | { | 705 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", |
699 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( | 706 | // m_PrimName, m_ScriptName, data.EventName, m_State); |
700 | m_LocalID); | ||
701 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", | ||
702 | // m_PrimName, m_ScriptName, data.EventName, m_State); | ||
703 | 707 | ||
704 | try | 708 | try |
705 | { | 709 | { |
706 | m_CurrentEvent = data.EventName; | 710 | m_CurrentEvent = data.EventName; |
707 | m_EventStart = DateTime.Now; | 711 | m_EventStart = DateTime.Now; |
708 | m_InEvent = true; | 712 | m_InEvent = true; |
709 | 713 | ||
710 | m_Script.ExecuteEvent(State, data.EventName, data.Params); | 714 | m_Script.ExecuteEvent(State, data.EventName, data.Params); |
711 | 715 | ||
712 | m_InEvent = false; | 716 | m_InEvent = false; |
713 | m_CurrentEvent = String.Empty; | 717 | m_CurrentEvent = String.Empty; |
714 | 718 | ||
715 | if (m_SaveState) | 719 | if (m_SaveState) |
716 | { | 720 | { |
717 | // This will be the very first event we deliver | 721 | // This will be the very first event we deliver |
718 | // (state_entry) in default state | 722 | // (state_entry) in default state |
719 | // | 723 | // |
720 | 724 | ||
721 | SaveState(m_Assembly); | 725 | SaveState(m_Assembly); |
722 | 726 | ||
723 | m_SaveState = false; | 727 | m_SaveState = false; |
724 | } | ||
725 | } | 728 | } |
726 | catch (Exception e) | 729 | } |
727 | { | 730 | catch (Exception e) |
728 | // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message); | 731 | { |
729 | m_InEvent = false; | 732 | // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message); |
730 | m_CurrentEvent = String.Empty; | 733 | m_InEvent = false; |
734 | m_CurrentEvent = String.Empty; | ||
731 | 735 | ||
732 | if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) | 736 | if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) |
733 | { | 737 | { |
734 | try | 738 | try |
735 | { | ||
736 | // DISPLAY ERROR INWORLD | ||
737 | string text = FormatException(e); | ||
738 | |||
739 | if (text.Length > 1000) | ||
740 | text = text.Substring(0, 1000); | ||
741 | m_Engine.World.SimChat(Utils.StringToBytes(text), | ||
742 | ChatTypeEnum.DebugChannel, 2147483647, | ||
743 | part.AbsolutePosition, | ||
744 | part.Name, part.UUID, false); | ||
745 | } | ||
746 | catch (Exception) | ||
747 | { | ||
748 | } | ||
749 | // catch (Exception e2) // LEGIT: User Scripting | ||
750 | // { | ||
751 | // m_log.Error("[SCRIPT]: "+ | ||
752 | // "Error displaying error in-world: " + | ||
753 | // e2.ToString()); | ||
754 | // m_log.Error("[SCRIPT]: " + | ||
755 | // "Errormessage: Error compiling script:\r\n" + | ||
756 | // e.ToString()); | ||
757 | // } | ||
758 | } | ||
759 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) | ||
760 | { | 739 | { |
761 | m_InSelfDelete = true; | 740 | // DISPLAY ERROR INWORLD |
762 | if (part != null && part.ParentGroup != null) | 741 | string text = FormatException(e); |
763 | m_Engine.World.DeleteSceneObject(part.ParentGroup, false); | 742 | |
743 | if (text.Length > 1000) | ||
744 | text = text.Substring(0, 1000); | ||
745 | m_Engine.World.SimChat(Utils.StringToBytes(text), | ||
746 | ChatTypeEnum.DebugChannel, 2147483647, | ||
747 | part.AbsolutePosition, | ||
748 | part.Name, part.UUID, false); | ||
764 | } | 749 | } |
765 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) | 750 | catch (Exception) |
766 | { | 751 | { |
767 | m_InSelfDelete = true; | ||
768 | if (part != null && part.ParentGroup != null) | ||
769 | part.Inventory.RemoveInventoryItem(m_ItemID); | ||
770 | } | 752 | } |
753 | // catch (Exception e2) // LEGIT: User Scripting | ||
754 | // { | ||
755 | // m_log.Error("[SCRIPT]: "+ | ||
756 | // "Error displaying error in-world: " + | ||
757 | // e2.ToString()); | ||
758 | // m_log.Error("[SCRIPT]: " + | ||
759 | // "Errormessage: Error compiling script:\r\n" + | ||
760 | // e.ToString()); | ||
761 | // } | ||
762 | } | ||
763 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) | ||
764 | { | ||
765 | m_InSelfDelete = true; | ||
766 | if (part != null && part.ParentGroup != null) | ||
767 | m_Engine.World.DeleteSceneObject(part.ParentGroup, false); | ||
768 | } | ||
769 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) | ||
770 | { | ||
771 | m_InSelfDelete = true; | ||
772 | if (part != null && part.ParentGroup != null) | ||
773 | part.Inventory.RemoveInventoryItem(m_ItemID); | ||
771 | } | 774 | } |
772 | } | 775 | } |
773 | } | 776 | } |
777 | } | ||
774 | 778 | ||
775 | lock (m_EventQueue) | 779 | lock (m_EventQueue) |
780 | { | ||
781 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) | ||
776 | { | 782 | { |
777 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) | 783 | m_CurrentResult = m_Engine.QueueEventHandler(this); |
778 | { | 784 | } |
779 | m_CurrentResult = m_Engine.QueueEventHandler(this); | 785 | else |
780 | } | 786 | { |
781 | else | 787 | m_CurrentResult = null; |
782 | { | ||
783 | m_CurrentResult = null; | ||
784 | } | ||
785 | } | 788 | } |
789 | } | ||
786 | 790 | ||
787 | m_DetectParams = null; | 791 | m_DetectParams = null; |
788 | 792 | ||
789 | return 0; | 793 | return 0; |
790 | } | 794 | } |
791 | } | 795 | } |
792 | 796 | ||
793 | public int EventTime() | 797 | public int EventTime() |