Improve DAExampleModule to show current necessary locking to avoid race conditions with a serialization thread.

user_profiles
Justin Clark-Casey (justincc) 2013-03-13 23:42:14 +00:00
parent 48d41ef307
commit 43220afda2
1 changed files with 16 additions and 8 deletions

View File

@ -85,19 +85,27 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule
{
OSDMap attrs = null;
SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId);
if (sop == null)
return true;
if (!sop.DynAttrs.TryGetValue(Name, out attrs))
attrs = new OSDMap();
OSDInteger newValue;
if (!attrs.ContainsKey("moves"))
newValue = new OSDInteger(1);
else
newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1);
attrs["moves"] = newValue;
sop.DynAttrs[Name] = attrs;
// We have to lock on the entire dynamic attributes map to avoid race conditions with serialization code.
lock (sop.DynAttrs)
{
if (!attrs.ContainsKey("moves"))
newValue = new OSDInteger(1);
else
newValue = new OSDInteger(attrs["moves"].AsInteger() + 1);
attrs["moves"] = newValue;
sop.DynAttrs[Name] = attrs;
}
m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue));