Relaxed the ultra-conservative lock on m_items. Needs testing under linux and stress.

0.7-release
Diva Canto 2010-07-20 05:59:18 -07:00
parent 257a46dfb9
commit d93a442483
1 changed files with 190 additions and 221 deletions

View File

@ -118,20 +118,20 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="linkNum">Link number for the part</param>
public void ResetInventoryIDs()
{
lock (Items)
lock (m_items)
{
if (0 == Items.Count)
if (0 == m_items.Count)
return;
HasInventoryChanged = true;
m_part.ParentGroup.HasGroupChanged = true;
IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
Items.Clear();
IList<TaskInventoryItem> items = GetInventoryItems();
m_items.Clear();
foreach (TaskInventoryItem item in items)
{
item.ResetIDs(m_part.UUID);
Items.Add(item.ItemID, item);
m_items.Add(item.ItemID, item);
}
}
}
@ -148,10 +148,11 @@ namespace OpenSim.Region.Framework.Scenes
{
return;
}
}
HasInventoryChanged = true;
m_part.ParentGroup.HasGroupChanged = true;
IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
List<TaskInventoryItem> items = GetInventoryItems();
foreach (TaskInventoryItem item in items)
{
if (ownerId != item.OwnerID)
@ -161,7 +162,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
}
/// <summary>
/// Change every item in this inventory to a new group.
@ -175,36 +175,27 @@ namespace OpenSim.Region.Framework.Scenes
{
return;
}
}
HasInventoryChanged = true;
m_part.ParentGroup.HasGroupChanged = true;
IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
List<TaskInventoryItem> items = GetInventoryItems();
foreach (TaskInventoryItem item in items)
{
if (groupID != item.GroupID)
{
item.GroupID = groupID;
}
}
}
}
/// <summary>
/// Start all the scripts contained in this prim's inventory
/// </summary>
public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
{
lock (m_items)
{
foreach (TaskInventoryItem item in Items.Values)
{
if ((int)InventoryType.LSL == item.InvType)
{
List<TaskInventoryItem> scripts = GetInventoryScripts();
foreach (TaskInventoryItem item in scripts)
CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
}
}
}
}
public ArrayList GetScriptErrors(UUID itemID)
{
@ -236,17 +227,10 @@ namespace OpenSim.Region.Framework.Scenes
/// </param>
public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
{
lock (Items)
{
foreach (TaskInventoryItem item in Items.Values)
{
if ((int)InventoryType.LSL == item.InvType)
{
List<TaskInventoryItem> scripts = GetInventoryScripts();
foreach (TaskInventoryItem item in scripts)
RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
}
}
}
}
/// <summary>
/// Start a script which is in this prim's inventory.
@ -375,22 +359,16 @@ namespace OpenSim.Region.Framework.Scenes
/// </param>
public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
{
lock (m_items)
{
if (m_items.ContainsKey(itemId))
{
CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
}
TaskInventoryItem item = GetInventoryItem(itemId);
if (item != null)
CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
else
{
m_log.ErrorFormat(
"[PRIM INVENTORY]: " +
"Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
itemId, m_part.Name, m_part.UUID,
m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
}
}
}
/// <summary>
/// Stop a script which is in this prim's inventory.
@ -430,17 +408,19 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary>
/// Check if the inventory holds an item with a given name.
/// This method assumes that the task inventory is already locked.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private bool InventoryContainsName(string name)
{
foreach (TaskInventoryItem item in Items.Values)
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
{
if (item.Name == name)
return true;
}
}
return false;
}
@ -482,12 +462,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="item"></param>
public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
{
List<TaskInventoryItem> il;
lock (m_items)
{
il = new List<TaskInventoryItem>(m_items.Values);
}
List<TaskInventoryItem> il = GetInventoryItems();
foreach (TaskInventoryItem i in il)
{
@ -527,14 +502,12 @@ namespace OpenSim.Region.Framework.Scenes
item.GroupID = m_part.GroupID;
lock (m_items)
{
m_items.Add(item.ItemID, item);
if (allowedDrop)
m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
else
m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
}
m_inventorySerial++;
//m_inventorySerial += 2;
@ -558,10 +531,9 @@ namespace OpenSim.Region.Framework.Scenes
m_items.Add(item.ItemID, item);
// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
}
}
m_inventorySerial++;
}
}
/// <summary>
/// Returns an existing inventory item. Returns the original, so any changes will be live.
@ -615,11 +587,8 @@ namespace OpenSim.Region.Framework.Scenes
public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents)
{
lock(m_items)
{
if (m_items.ContainsKey(item.ItemID))
{
if (m_items.ContainsKey(item.ItemID))
TaskInventoryItem it = GetInventoryItem(item.ItemID);
if (it != null)
{
item.ParentID = m_part.UUID;
item.ParentPartID = m_part.UUID;
@ -631,13 +600,17 @@ namespace OpenSim.Region.Framework.Scenes
item.GroupID = m_part.GroupID;
if (item.AssetID == UUID.Zero)
item.AssetID = it.AssetID;
lock (m_items)
{
item.AssetID = m_items[item.ItemID].AssetID;
}
m_items[item.ItemID] = item;
m_inventorySerial++;
}
if (fireScriptEvents)
m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
HasInventoryChanged = true;
m_part.ParentGroup.HasGroupChanged = true;
return true;
@ -650,10 +623,8 @@ namespace OpenSim.Region.Framework.Scenes
item.ItemID, m_part.Name, m_part.UUID,
m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
}
}
return false;
}
}
/// <summary>
@ -664,9 +635,8 @@ namespace OpenSim.Region.Framework.Scenes
/// in this prim's inventory.</returns>
public int RemoveInventoryItem(UUID itemID)
{
lock (m_items)
{
if (m_items.ContainsKey(itemID))
TaskInventoryItem item = GetInventoryItem(itemID);
if (item != null)
{
int type = m_items[itemID].InvType;
if (type == 10) // Script
@ -681,26 +651,13 @@ namespace OpenSim.Region.Framework.Scenes
HasInventoryChanged = true;
m_part.ParentGroup.HasGroupChanged = true;
int scriptcount = 0;
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
{
if (item.Type == 10)
{
scriptcount++;
}
}
}
if (scriptcount <= 0)
{
if (!ContainsScripts())
m_part.RemFlag(PrimFlags.Scripted);
}
m_part.ScheduleFullUpdate();
return type;
}
else
{
@ -710,7 +667,6 @@ namespace OpenSim.Region.Framework.Scenes
itemID, m_part.Name, m_part.UUID,
m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
}
}
return -1;
}
@ -763,9 +719,8 @@ namespace OpenSim.Region.Framework.Scenes
// isn't available (such as drag from prim inventory to agent inventory)
InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
List<TaskInventoryItem> items = GetInventoryItems();
foreach (TaskInventoryItem item in items)
{
UUID ownerID = item.OwnerID;
uint everyoneMask = 0;
@ -809,7 +764,6 @@ namespace OpenSim.Region.Framework.Scenes
invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
invString.AddSectionEnd();
}
}
fileData = Utils.StringToBytes(invString.BuildString);
@ -830,12 +784,10 @@ namespace OpenSim.Region.Framework.Scenes
{
if (HasInventoryChanged)
{
lock (Items)
{
datastore.StorePrimInventory(m_part.UUID, Items.Values);
}
HasInventoryChanged = false;
List<TaskInventoryItem> items = GetInventoryItems();
datastore.StorePrimInventory(m_part.UUID, items);
}
}
@ -1002,6 +954,30 @@ namespace OpenSim.Region.Framework.Scenes
return ret;
}
public List<TaskInventoryItem> GetInventoryItems()
{
List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
lock (m_items)
ret = new List<TaskInventoryItem>(m_items.Values);
return ret;
}
public List<TaskInventoryItem> GetInventoryScripts()
{
List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
if (item.InvType == (int)InventoryType.LSL)
ret.Add(item);
}
return ret;
}
public Dictionary<UUID, string> GetScriptStates()
{
IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
@ -1010,11 +986,9 @@ namespace OpenSim.Region.Framework.Scenes
if (engines == null) // No engine at all
return ret;
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
{
if (item.InvType == (int)InventoryType.LSL)
List<TaskInventoryItem> scripts = GetInventoryScripts();
foreach (TaskInventoryItem item in scripts)
{
foreach (IScriptModule e in engines)
{
@ -1030,8 +1004,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
}
}
return ret;
}
@ -1042,11 +1014,9 @@ namespace OpenSim.Region.Framework.Scenes
if (engines == null)
return;
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
{
if (item.InvType == (int)InventoryType.LSL)
List<TaskInventoryItem> scripts = GetInventoryScripts();
foreach (TaskInventoryItem item in scripts)
{
foreach (IScriptModule engine in engines)
{
@ -1060,7 +1030,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
}
}
}
}