improve locking of m_items in SceneObjectPartInventory

mysql-performance
Justin Clark-Casey (justincc) 2010-01-29 20:36:13 +00:00
parent ae2174d8f5
commit 968b9e160d
1 changed files with 133 additions and 85 deletions

View File

@ -44,6 +44,8 @@ namespace OpenSim.Region.Framework.Scenes
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
private string m_inventoryFileName = String.Empty; private string m_inventoryFileName = String.Empty;
private int m_inventoryFileNameSerial = 0; private int m_inventoryFileNameSerial = 0;
@ -270,8 +272,12 @@ namespace OpenSim.Region.Framework.Scenes
if (stateSource == 1 && // Prim crossing if (stateSource == 1 && // Prim crossing
m_part.ParentGroup.Scene.m_trustBinaries) m_part.ParentGroup.Scene.m_trustBinaries)
{ {
m_items[item.ItemID].PermsMask = 0; lock (m_items)
m_items[item.ItemID].PermsGranter = UUID.Zero; {
m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero;
}
m_part.ParentGroup.Scene.EventManager.TriggerRezScript( m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
m_part.ParentGroup.AddActiveScriptCount(1); m_part.ParentGroup.AddActiveScriptCount(1);
@ -279,33 +285,38 @@ namespace OpenSim.Region.Framework.Scenes
return; return;
} }
m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) m_part.ParentGroup.Scene.AssetService.Get(
{ item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset)
if (null == asset) {
{ if (null == asset)
m_log.ErrorFormat( {
"[PRIM INVENTORY]: " + m_log.ErrorFormat(
"Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", "[PRIM INVENTORY]: " +
item.Name, item.ItemID, m_part.AbsolutePosition, "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); item.Name, item.ItemID, m_part.AbsolutePosition,
} m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
else }
{ else
if (m_part.ParentGroup.m_savedScriptState != null) {
RestoreSavedScriptState(item.OldItemID, item.ItemID); if (m_part.ParentGroup.m_savedScriptState != null)
m_items[item.ItemID].PermsMask = 0; RestoreSavedScriptState(item.OldItemID, item.ItemID);
m_items[item.ItemID].PermsGranter = UUID.Zero;
string script = Utils.BytesToString(asset.Data);
m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
m_part.ParentGroup.AddActiveScriptCount(1);
m_part.ScheduleFullUpdate();
}
});
}
}
static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); lock (m_items)
{
m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero;
}
string script = Utils.BytesToString(asset.Data);
m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
m_part.ParentGroup.AddActiveScriptCount(1);
m_part.ScheduleFullUpdate();
}
}
);
}
}
private void RestoreSavedScriptState(UUID oldID, UUID newID) private void RestoreSavedScriptState(UUID oldID, UUID newID)
{ {
@ -397,7 +408,15 @@ namespace OpenSim.Region.Framework.Scenes
/// </param> /// </param>
public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
{ {
if (m_items.ContainsKey(itemId)) bool scriptPresent = false;
lock (m_items)
{
if (m_items.ContainsKey(itemId))
scriptPresent = true;
}
if (scriptPresent)
{ {
if (!sceneObjectBeingDeleted) if (!sceneObjectBeingDeleted)
m_part.RemoveScriptEvents(itemId); m_part.RemoveScriptEvents(itemId);
@ -469,7 +488,13 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="item"></param> /// <param name="item"></param>
public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
{ {
List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values); List<TaskInventoryItem> il;
lock (m_items)
{
il = new List<TaskInventoryItem>(m_items.Values);
}
foreach (TaskInventoryItem i in il) foreach (TaskInventoryItem i in il)
{ {
if (i.Name == item.Name) if (i.Name == item.Name)
@ -551,7 +576,9 @@ namespace OpenSim.Region.Framework.Scenes
public TaskInventoryItem GetInventoryItem(UUID itemId) public TaskInventoryItem GetInventoryItem(UUID itemId)
{ {
TaskInventoryItem item; TaskInventoryItem item;
m_items.TryGetValue(itemId, out item);
lock (m_items)
m_items.TryGetValue(itemId, out item);
return item; return item;
} }
@ -877,54 +904,61 @@ namespace OpenSim.Region.Framework.Scenes
{ {
uint mask=0x7fffffff; uint mask=0x7fffffff;
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
{ {
if (item.InvType != (int)InventoryType.Object) foreach (TaskInventoryItem item in m_items.Values)
{ {
if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) if (item.InvType != (int)InventoryType.Object)
mask &= ~((uint)PermissionMask.Copy >> 13); {
if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
mask &= ~((uint)PermissionMask.Transfer >> 13); mask &= ~((uint)PermissionMask.Copy >> 13);
if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
mask &= ~((uint)PermissionMask.Modify >> 13); mask &= ~((uint)PermissionMask.Transfer >> 13);
if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
mask &= ~((uint)PermissionMask.Modify >> 13);
}
else
{
if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
mask &= ~((uint)PermissionMask.Copy >> 13);
if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
mask &= ~((uint)PermissionMask.Transfer >> 13);
if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
mask &= ~((uint)PermissionMask.Modify >> 13);
}
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
mask &= ~(uint)PermissionMask.Copy;
if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
mask &= ~(uint)PermissionMask.Transfer;
if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
mask &= ~(uint)PermissionMask.Modify;
} }
else
{
if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
mask &= ~((uint)PermissionMask.Copy >> 13);
if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
mask &= ~((uint)PermissionMask.Transfer >> 13);
if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
mask &= ~((uint)PermissionMask.Modify >> 13);
}
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
mask &= ~(uint)PermissionMask.Copy;
if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
mask &= ~(uint)PermissionMask.Transfer;
if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
mask &= ~(uint)PermissionMask.Modify;
} }
return mask; return mask;
} }
public void ApplyNextOwnerPermissions() public void ApplyNextOwnerPermissions()
{ {
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
{ {
if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) foreach (TaskInventoryItem item in m_items.Values)
{ {
if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
item.CurrentPermissions &= ~(uint)PermissionMask.Copy; {
if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
item.CurrentPermissions &= ~(uint)PermissionMask.Modify; item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
item.CurrentPermissions |= 8; if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
item.CurrentPermissions |= 8;
}
item.CurrentPermissions &= item.NextPermissions;
item.BasePermissions &= item.NextPermissions;
item.EveryonePermissions &= item.NextPermissions;
} }
item.CurrentPermissions &= item.NextPermissions;
item.BasePermissions &= item.NextPermissions;
item.EveryonePermissions &= item.NextPermissions;
} }
m_part.TriggerScriptChangedEvent(Changed.OWNER); m_part.TriggerScriptChangedEvent(Changed.OWNER);
@ -932,22 +966,29 @@ namespace OpenSim.Region.Framework.Scenes
public void ApplyGodPermissions(uint perms) public void ApplyGodPermissions(uint perms)
{ {
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
{ {
item.CurrentPermissions = perms; foreach (TaskInventoryItem item in m_items.Values)
item.BasePermissions = perms; {
item.CurrentPermissions = perms;
item.BasePermissions = perms;
}
} }
} }
public bool ContainsScripts() public bool ContainsScripts()
{ {
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
{ {
if (item.InvType == (int)InventoryType.LSL) foreach (TaskInventoryItem item in m_items.Values)
{ {
return true; if (item.InvType == (int)InventoryType.LSL)
{
return true;
}
} }
} }
return false; return false;
} }
@ -955,8 +996,11 @@ namespace OpenSim.Region.Framework.Scenes
{ {
List<UUID> ret = new List<UUID>(); List<UUID> ret = new List<UUID>();
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
ret.Add(item.ItemID); {
foreach (TaskInventoryItem item in m_items.Values)
ret.Add(item.ItemID);
}
return ret; return ret;
} }
@ -969,26 +1013,30 @@ namespace OpenSim.Region.Framework.Scenes
if (engines == null) // No engine at all if (engines == null) // No engine at all
return ret; return ret;
foreach (TaskInventoryItem item in m_items.Values) lock (m_items)
{ {
if (item.InvType == (int)InventoryType.LSL) foreach (TaskInventoryItem item in m_items.Values)
{ {
foreach (IScriptModule e in engines) if (item.InvType == (int)InventoryType.LSL)
{ {
if (e != null) foreach (IScriptModule e in engines)
{ {
string n = e.GetXMLState(item.ItemID); if (e != null)
if (n != String.Empty)
{ {
if (!ret.ContainsKey(item.ItemID)) string n = e.GetXMLState(item.ItemID);
ret[item.ItemID] = n; if (n != String.Empty)
break; {
if (!ret.ContainsKey(item.ItemID))
ret[item.ItemID] = n;
break;
}
} }
} }
} }
} }
} }
return ret; return ret;
} }
} }
} }