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;
@ -269,9 +271,13 @@ 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)
{
lock (m_items)
{ {
m_items[item.ItemID].PermsMask = 0; m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero; 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,7 +285,8 @@ 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)
{ {
@ -293,20 +300,24 @@ namespace OpenSim.Region.Framework.Scenes
{ {
if (m_part.ParentGroup.m_savedScriptState != null) if (m_part.ParentGroup.m_savedScriptState != null)
RestoreSavedScriptState(item.OldItemID, item.ItemID); RestoreSavedScriptState(item.OldItemID, item.ItemID);
lock (m_items)
{
m_items[item.ItemID].PermsMask = 0; m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero; m_items[item.ItemID].PermsGranter = UUID.Zero;
}
string script = Utils.BytesToString(asset.Data); string script = Utils.BytesToString(asset.Data);
m_part.ParentGroup.Scene.EventManager.TriggerRezScript( m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
m_part.ParentGroup.AddActiveScriptCount(1); m_part.ParentGroup.AddActiveScriptCount(1);
m_part.ScheduleFullUpdate(); m_part.ScheduleFullUpdate();
} }
}); }
);
} }
} }
static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
private void RestoreSavedScriptState(UUID oldID, UUID newID) private void RestoreSavedScriptState(UUID oldID, UUID newID)
{ {
IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>(); IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
@ -396,8 +407,16 @@ namespace OpenSim.Region.Framework.Scenes
/// object is being deleted. This will prevent spurious updates to the client. /// object is being deleted. This will prevent spurious updates to the client.
/// </param> /// </param>
public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
{
bool scriptPresent = false;
lock (m_items)
{ {
if (m_items.ContainsKey(itemId)) 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,6 +576,8 @@ namespace OpenSim.Region.Framework.Scenes
public TaskInventoryItem GetInventoryItem(UUID itemId) public TaskInventoryItem GetInventoryItem(UUID itemId)
{ {
TaskInventoryItem item; TaskInventoryItem item;
lock (m_items)
m_items.TryGetValue(itemId, out item); m_items.TryGetValue(itemId, out item);
return item; return item;
@ -877,6 +904,8 @@ namespace OpenSim.Region.Framework.Scenes
{ {
uint mask=0x7fffffff; uint mask=0x7fffffff;
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
if (item.InvType != (int)InventoryType.Object) if (item.InvType != (int)InventoryType.Object)
@ -905,10 +934,14 @@ namespace OpenSim.Region.Framework.Scenes
if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
mask &= ~(uint)PermissionMask.Modify; mask &= ~(uint)PermissionMask.Modify;
} }
}
return mask; return mask;
} }
public void ApplyNextOwnerPermissions() public void ApplyNextOwnerPermissions()
{
lock (m_items)
{ {
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
@ -926,11 +959,14 @@ namespace OpenSim.Region.Framework.Scenes
item.BasePermissions &= item.NextPermissions; item.BasePermissions &= item.NextPermissions;
item.EveryonePermissions &= item.NextPermissions; item.EveryonePermissions &= item.NextPermissions;
} }
}
m_part.TriggerScriptChangedEvent(Changed.OWNER); m_part.TriggerScriptChangedEvent(Changed.OWNER);
} }
public void ApplyGodPermissions(uint perms) public void ApplyGodPermissions(uint perms)
{
lock (m_items)
{ {
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
@ -938,8 +974,11 @@ namespace OpenSim.Region.Framework.Scenes
item.BasePermissions = perms; item.BasePermissions = perms;
} }
} }
}
public bool ContainsScripts() public bool ContainsScripts()
{
lock (m_items)
{ {
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
@ -948,6 +987,8 @@ namespace OpenSim.Region.Framework.Scenes
return true; 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>();
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
ret.Add(item.ItemID); ret.Add(item.ItemID);
}
return ret; return ret;
} }
@ -969,6 +1013,8 @@ namespace OpenSim.Region.Framework.Scenes
if (engines == null) // No engine at all if (engines == null) // No engine at all
return ret; return ret;
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
if (item.InvType == (int)InventoryType.LSL) if (item.InvType == (int)InventoryType.LSL)
@ -988,6 +1034,8 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
return ret; return ret;
} }
} }