diff options
author | Justin Clark-Casey (justincc) | 2011-08-31 16:29:51 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-08-31 16:29:51 +0100 |
commit | 32444d98cb13423fdf8c874e4fbb7ea17670d7c5 (patch) | |
tree | 4c384f277afc6138a050706eaaf839caeed22d1d /OpenSim/Region/Framework | |
parent | remove pointless ToArray() call in AttachmentsModule.SaveChangedAttachments() (diff) | |
download | opensim-SC-32444d98cb13423fdf8c874e4fbb7ea17670d7c5.zip opensim-SC-32444d98cb13423fdf8c874e4fbb7ea17670d7c5.tar.gz opensim-SC-32444d98cb13423fdf8c874e4fbb7ea17670d7c5.tar.bz2 opensim-SC-32444d98cb13423fdf8c874e4fbb7ea17670d7c5.tar.xz |
Make SP.Attachments available as sp.GetAttachments() instead.
The approach here, as in other parts of OpenSim, is to return a copy of the list rather than the attachments list itself
This prevents callers from forgetting to lock the list when they read it, as was happening in various parts of the codebase.
It also improves liveness.
This might improve attachment anomolies when performing region crossings.
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/IScenePresence.cs | 7 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 51 |
2 files changed, 43 insertions, 15 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs index b07c821..788b36f 100644 --- a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs +++ b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs | |||
@@ -58,10 +58,13 @@ namespace OpenSim.Region.Framework.Interfaces | |||
58 | /// <summary> | 58 | /// <summary> |
59 | /// The scene objects attached to this avatar. | 59 | /// The scene objects attached to this avatar. |
60 | /// </summary> | 60 | /// </summary> |
61 | /// <returns> | ||
62 | /// A copy of the list. | ||
63 | /// </returns> | ||
61 | /// <remarks> | 64 | /// <remarks> |
62 | /// Do not change this list directly - use methods such as | 65 | /// Do not change this list directly - use methods such as |
63 | /// AddAttachment() and RemoveAttachment(). Lock this list when performing any read operations upon it. | 66 | /// AddAttachment() and RemoveAttachment(). |
64 | /// </remarks> | 67 | /// </remarks> |
65 | List<SceneObjectGroup> Attachments { get; } | 68 | List<SceneObjectGroup> GetAttachments(); |
66 | } | 69 | } |
67 | } \ No newline at end of file | 70 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 0a91989..f5c72e1 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -114,10 +114,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
114 | } | 114 | } |
115 | protected ScenePresenceAnimator m_animator; | 115 | protected ScenePresenceAnimator m_animator; |
116 | 116 | ||
117 | public List<SceneObjectGroup> Attachments | 117 | /// <summary> |
118 | { | 118 | /// Attachments recorded on this avatar. |
119 | get { return m_attachments; } | 119 | /// </summary> |
120 | } | 120 | /// <remarks> |
121 | /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is | ||
122 | /// necessary. | ||
123 | /// </remarks> | ||
121 | protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); | 124 | protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); |
122 | 125 | ||
123 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); | 126 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); |
@@ -940,15 +943,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
940 | // and it has already rezzed the attachments and started their scripts. | 943 | // and it has already rezzed the attachments and started their scripts. |
941 | // We do the following only for non-login agents, because their scripts | 944 | // We do the following only for non-login agents, because their scripts |
942 | // haven't started yet. | 945 | // haven't started yet. |
943 | if (wasChild && Attachments != null && Attachments.Count > 0) | 946 | lock (m_attachments) |
944 | { | 947 | { |
945 | m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); | 948 | if (wasChild && m_attachments != null && m_attachments.Count > 0) |
946 | // Resume scripts | ||
947 | Attachments.ForEach(delegate(SceneObjectGroup sog) | ||
948 | { | 949 | { |
949 | sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); | 950 | m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); |
950 | sog.ResumeScripts(); | 951 | // Resume scripts |
951 | }); | 952 | foreach (SceneObjectGroup sog in m_attachments) |
953 | { | ||
954 | sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); | ||
955 | sog.ResumeScripts(); | ||
956 | } | ||
957 | } | ||
952 | } | 958 | } |
953 | 959 | ||
954 | // send the animations of the other presences to me | 960 | // send the animations of the other presences to me |
@@ -3472,9 +3478,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
3472 | m_attachments.Add(gobj); | 3478 | m_attachments.Add(gobj); |
3473 | } | 3479 | } |
3474 | } | 3480 | } |
3475 | 3481 | ||
3476 | /// <summary> | 3482 | /// <summary> |
3477 | /// Get the scene object attached to the given point. | 3483 | /// Get all the presence's attachments. |
3484 | /// </summary> | ||
3485 | /// <returns>A copy of the list which contains the attachments.</returns> | ||
3486 | public List<SceneObjectGroup> GetAttachments() | ||
3487 | { | ||
3488 | lock (m_attachments) | ||
3489 | return new List<SceneObjectGroup>(m_attachments); | ||
3490 | } | ||
3491 | |||
3492 | /// <summary> | ||
3493 | /// Get the scene objects attached to the given point. | ||
3478 | /// </summary> | 3494 | /// </summary> |
3479 | /// <param name="attachmentPoint"></param> | 3495 | /// <param name="attachmentPoint"></param> |
3480 | /// <returns>Returns an empty list if there were no attachments at the point.</returns> | 3496 | /// <returns>Returns an empty list if there were no attachments at the point.</returns> |
@@ -3521,6 +3537,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
3521 | m_attachments.Remove(gobj); | 3537 | m_attachments.Remove(gobj); |
3522 | } | 3538 | } |
3523 | 3539 | ||
3540 | /// <summary> | ||
3541 | /// Clear all attachments | ||
3542 | /// </summary> | ||
3543 | public void ClearAttachments() | ||
3544 | { | ||
3545 | lock (m_attachments) | ||
3546 | m_attachments.Clear(); | ||
3547 | } | ||
3548 | |||
3524 | public bool ValidateAttachments() | 3549 | public bool ValidateAttachments() |
3525 | { | 3550 | { |
3526 | lock (m_attachments) | 3551 | lock (m_attachments) |