Rewrote parts of the code that were double-locking different objects. This is about half of the code base reviewed.

prioritization
Diva Canto 2009-10-06 15:39:53 -07:00
parent 99c85b5ef5
commit e992ca0255
9 changed files with 211 additions and 176 deletions

View File

@ -128,16 +128,12 @@ namespace OpenSim.Framework.Communications.Cache
/// <returns>null if no user details are found</returns> /// <returns>null if no user details are found</returns>
public CachedUserInfo GetUserDetails(string fname, string lname) public CachedUserInfo GetUserDetails(string fname, string lname)
{ {
CachedUserInfo userInfo;
lock (m_userProfilesByName) lock (m_userProfilesByName)
{ {
CachedUserInfo userInfo;
if (m_userProfilesByName.TryGetValue(string.Format(NAME_FORMAT, fname, lname), out userInfo)) if (m_userProfilesByName.TryGetValue(string.Format(NAME_FORMAT, fname, lname), out userInfo))
{
return userInfo; return userInfo;
} }
else
{
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname); UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname);
if (userProfile != null) if (userProfile != null)
@ -145,8 +141,6 @@ namespace OpenSim.Framework.Communications.Cache
else else
return null; return null;
} }
}
}
/// <summary> /// <summary>
/// Get details of the given user. /// Get details of the given user.
@ -160,21 +154,15 @@ namespace OpenSim.Framework.Communications.Cache
return null; return null;
lock (m_userProfilesById) lock (m_userProfilesById)
{
if (m_userProfilesById.ContainsKey(userID)) if (m_userProfilesById.ContainsKey(userID))
{
return m_userProfilesById[userID]; return m_userProfilesById[userID];
}
else
{
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID); UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID);
if (userProfile != null) if (userProfile != null)
return AddToCaches(userProfile); return AddToCaches(userProfile);
else else
return null; return null;
} }
}
}
/// <summary> /// <summary>
/// Update an existing profile /// Update an existing profile
@ -211,14 +199,10 @@ namespace OpenSim.Framework.Communications.Cache
CachedUserInfo createdUserInfo = new CachedUserInfo(m_InventoryService, userProfile); CachedUserInfo createdUserInfo = new CachedUserInfo(m_InventoryService, userProfile);
lock (m_userProfilesById) lock (m_userProfilesById)
{
m_userProfilesById[createdUserInfo.UserProfile.ID] = createdUserInfo; m_userProfilesById[createdUserInfo.UserProfile.ID] = createdUserInfo;
lock (m_userProfilesByName) lock (m_userProfilesByName)
{
m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo; m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo;
}
}
return createdUserInfo; return createdUserInfo;
} }
@ -230,18 +214,22 @@ namespace OpenSim.Framework.Communications.Cache
/// <returns>true if there was a profile to remove, false otherwise</returns> /// <returns>true if there was a profile to remove, false otherwise</returns>
protected bool RemoveFromCaches(UUID userId) protected bool RemoveFromCaches(UUID userId)
{ {
CachedUserInfo userInfo = null;
lock (m_userProfilesById) lock (m_userProfilesById)
{ {
if (m_userProfilesById.ContainsKey(userId)) if (m_userProfilesById.ContainsKey(userId))
{ {
CachedUserInfo userInfo = m_userProfilesById[userId]; userInfo = m_userProfilesById[userId];
m_userProfilesById.Remove(userId); m_userProfilesById.Remove(userId);
}
lock (m_userProfilesByName)
{
m_userProfilesByName.Remove(userInfo.UserProfile.Name);
} }
if (userInfo != null)
lock (m_userProfilesByName)
{
if (m_userProfilesByName.ContainsKey(userInfo.UserProfile.Name))
{
m_userProfilesByName.Remove(userInfo.UserProfile.Name);
return true; return true;
} }
} }

View File

@ -3122,6 +3122,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
objectData.TextureAnim = textureanim; objectData.TextureAnim = textureanim;
} }
bool doUpdate = false;
lock (m_primFullUpdates) lock (m_primFullUpdates)
{ {
if (m_primFullUpdates.Count == 0) if (m_primFullUpdates.Count == 0)
@ -3130,8 +3131,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_primFullUpdates.Add(objectData); m_primFullUpdates.Add(objectData);
if (m_primFullUpdates.Count >= m_primFullUpdatesPerPacket) if (m_primFullUpdates.Count >= m_primFullUpdatesPerPacket)
ProcessPrimFullUpdates(this, null); doUpdate = true;
} }
if (doUpdate)
ProcessPrimFullUpdates(this, null);
} }
void HandleQueueEmpty(ThrottleOutPacketType queue) void HandleQueueEmpty(ThrottleOutPacketType queue)
@ -3152,13 +3155,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
void ProcessPrimFullUpdates(object sender, ElapsedEventArgs e) void ProcessPrimFullUpdates(object sender, ElapsedEventArgs e)
{ {
bool stopTimer = false;
lock (m_primFullUpdates) lock (m_primFullUpdates)
{ {
if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled) if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled)
stopTimer = true;
}
if (stopTimer)
{ {
lock (m_primFullUpdateTimer) lock (m_primFullUpdateTimer)
m_primFullUpdateTimer.Stop(); m_primFullUpdateTimer.Stop();
return; return;
} }
@ -3181,6 +3187,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
byte[] zerobuffer = new byte[1024]; byte[] zerobuffer = new byte[1024];
byte[] blockbuffer = new byte[1024]; byte[] blockbuffer = new byte[1024];
lock (m_primFullUpdates)
{
for (count = 0 ; count < max ; count++) for (count = 0 ; count < max ; count++)
{ {
int length = 0; int length = 0;
@ -3204,10 +3212,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority); OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority);
if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled) if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled)
stopTimer = true;
}
if (stopTimer)
lock (m_primFullUpdateTimer) lock (m_primFullUpdateTimer)
m_primFullUpdateTimer.Stop(); m_primFullUpdateTimer.Stop();
} }
}
/// <summary> /// <summary>
/// ///
@ -3225,6 +3236,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
CreatePrimImprovedBlock(localID, position, rotation, CreatePrimImprovedBlock(localID, position, rotation,
velocity, rotationalvelocity, state); velocity, rotationalvelocity, state);
bool doUpdate = false;
lock (m_primTerseUpdates) lock (m_primTerseUpdates)
{ {
if (m_primTerseUpdates.Count == 0) if (m_primTerseUpdates.Count == 0)
@ -3233,15 +3245,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_primTerseUpdates.Add(objectData); m_primTerseUpdates.Add(objectData);
if (m_primTerseUpdates.Count >= m_primTerseUpdatesPerPacket) if (m_primTerseUpdates.Count >= m_primTerseUpdatesPerPacket)
ProcessPrimTerseUpdates(this, null); doUpdate = true;
} }
if (doUpdate)
ProcessPrimTerseUpdates(this, null);
} }
void ProcessPrimTerseUpdates(object sender, ElapsedEventArgs e) void ProcessPrimTerseUpdates(object sender, ElapsedEventArgs e)
{ {
bool stopTimer = false;
lock (m_primTerseUpdates) lock (m_primTerseUpdates)
{ {
if (m_primTerseUpdates.Count == 0) if (m_primTerseUpdates.Count == 0)
stopTimer = true;
}
if (stopTimer)
{ {
lock (m_primTerseUpdateTimer) lock (m_primTerseUpdateTimer)
m_primTerseUpdateTimer.Stop(); m_primTerseUpdateTimer.Stop();
@ -3269,7 +3287,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
byte[] zerobuffer = new byte[1024]; byte[] zerobuffer = new byte[1024];
byte[] blockbuffer = new byte[1024]; byte[] blockbuffer = new byte[1024];
for (count = 0 ; count < max ; count++) lock (m_primTerseUpdates)
{
for (count = 0; count < max; count++)
{ {
int length = 0; int length = 0;
m_primTerseUpdates[count].ToBytes(blockbuffer, ref length); m_primTerseUpdates[count].ToBytes(blockbuffer, ref length);
@ -3294,10 +3314,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority); OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority);
if (m_primTerseUpdates.Count == 0) if (m_primTerseUpdates.Count == 0)
stopTimer = true;
}
if (stopTimer)
lock (m_primTerseUpdateTimer) lock (m_primTerseUpdateTimer)
m_primTerseUpdateTimer.Stop(); m_primTerseUpdateTimer.Stop();
} }
}
public void FlushPrimUpdates() public void FlushPrimUpdates()
{ {

View File

@ -442,11 +442,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
private ScenePresence GetRootPresenceFromAgentID(UUID AgentID) private ScenePresence GetRootPresenceFromAgentID(UUID AgentID)
{ {
ScenePresence returnAgent = null; List<Scene> scenes = null;
lock (m_scenes) lock (m_scenes)
{ scenes = new List<Scene>(m_scenes.Values);
ScenePresence returnAgent = null;
ScenePresence queryagent = null; ScenePresence queryagent = null;
foreach (Scene scene in m_scenes.Values) foreach (Scene scene in scenes)
{ {
queryagent = scene.GetScenePresence(AgentID); queryagent = scene.GetScenePresence(AgentID);
if (queryagent != null) if (queryagent != null)
@ -458,15 +460,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
} }
} }
}
return returnAgent; return returnAgent;
} }
private ScenePresence GetAnyPresenceFromAgentID(UUID AgentID) private ScenePresence GetAnyPresenceFromAgentID(UUID AgentID)
{ {
ScenePresence returnAgent = null; List<Scene> scenes = null;
lock (m_scenes) lock (m_scenes)
{ scenes = new List<Scene>(m_scenes.Values);
ScenePresence returnAgent = null;
ScenePresence queryagent = null; ScenePresence queryagent = null;
foreach (Scene scene in m_scenes.Values) foreach (Scene scene in m_scenes.Values)
{ {
@ -477,7 +481,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
break; break;
} }
} }
}
return returnAgent; return returnAgent;
} }

View File

@ -290,14 +290,15 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
// get the agent. This should work every time, as we just got a packet from it // get the agent. This should work every time, as we just got a packet from it
ScenePresence agent = null; ScenePresence agent = null;
List<Scene> scenes = null;
lock (m_Scenes) lock (m_Scenes)
{ scenes = new List<Scene>(m_Scenes);
foreach (Scene scene in m_Scenes)
foreach (Scene scene in scenes)
{ {
agent = scene.GetScenePresence(agentID); agent = scene.GetScenePresence(agentID);
if (agent != null) break; if (agent != null) break;
} }
}
// just to be paranoid... // just to be paranoid...
if (agent == null) if (agent == null)

View File

@ -111,9 +111,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
private Scene FindClientScene(UUID agentId) private Scene FindClientScene(UUID agentId)
{ {
List<Scene> scenes = null;
lock (m_Scenelist) lock (m_Scenelist)
{ scenes = new List<Scene>(m_Scenelist);
foreach (Scene scene in m_Scenelist)
foreach (Scene scene in scenes)
{ {
ScenePresence presence = scene.GetScenePresence(agentId); ScenePresence presence = scene.GetScenePresence(agentId);
if (presence != null) if (presence != null)
@ -122,7 +124,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
return scene; return scene;
} }
} }
}
return null; return null;
} }

View File

@ -198,9 +198,11 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName) private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName)
{ {
List<Scene> scenes = null;
lock (m_Scenes) lock (m_Scenes)
{ scenes = new List<Scene>(m_Scenes.Values);
foreach (Scene s in m_Scenes.Values)
foreach (Scene s in scenes)
{ {
SceneObjectPart part = s.GetSceneObjectPart(objectID); SceneObjectPart part = s.GetSceneObjectPart(objectID);
if (part != null) if (part != null)
@ -212,7 +214,6 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
return part; return part;
} }
} }
}
ObjectRegionName = string.Empty; ObjectRegionName = string.Empty;
return null; return null;
} }
@ -363,6 +364,7 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
public Email GetNextEmail(UUID objectID, string sender, string subject) public Email GetNextEmail(UUID objectID, string sender, string subject)
{ {
List<Email> queue = null; List<Email> queue = null;
List<UUID> removal = new List<UUID>();
lock (m_LastGetEmailCall) lock (m_LastGetEmailCall)
{ {
@ -375,7 +377,6 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
// Hopefully this isn't too time consuming. If it is, we can always push it into a worker thread. // Hopefully this isn't too time consuming. If it is, we can always push it into a worker thread.
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
List<UUID> removal = new List<UUID>();
foreach (UUID uuid in m_LastGetEmailCall.Keys) foreach (UUID uuid in m_LastGetEmailCall.Keys)
{ {
if ((now - m_LastGetEmailCall[uuid]) > m_QueueTimeout) if ((now - m_LastGetEmailCall[uuid]) > m_QueueTimeout)
@ -383,16 +384,16 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
removal.Add(uuid); removal.Add(uuid);
} }
} }
}
foreach (UUID remove in removal) foreach (UUID remove in removal)
{ {
lock (m_LastGetEmailCall)
m_LastGetEmailCall.Remove(remove); m_LastGetEmailCall.Remove(remove);
lock (m_MailQueues) lock (m_MailQueues)
{
m_MailQueues.Remove(remove); m_MailQueues.Remove(remove);
} }
}
}
lock (m_MailQueues) lock (m_MailQueues)
{ {

View File

@ -187,14 +187,16 @@ namespace OpenSim.Region.CoreModules.World.Land
LandData newData = data.Copy(); LandData newData = data.Copy();
newData.LocalID = local_id; newData.LocalID = local_id;
ILandObject land = null;
lock (m_landList) lock (m_landList)
{ {
if (m_landList.ContainsKey(local_id)) if (m_landList.ContainsKey(local_id))
{ {
m_landList[local_id].LandData = newData; m_landList[local_id].LandData = newData;
m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, m_landList[local_id]); land = m_landList[local_id];
} }
} }
m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land);
} }
public bool AllowedForcefulBans public bool AllowedForcefulBans
@ -504,6 +506,7 @@ namespace OpenSim.Region.CoreModules.World.Land
/// <param name="local_id">Land.localID of the peice of land to remove.</param> /// <param name="local_id">Land.localID of the peice of land to remove.</param>
public void removeLandObject(int local_id) public void removeLandObject(int local_id)
{ {
UUID id = UUID.Zero;
lock (m_landList) lock (m_landList)
{ {
for (int x = 0; x < 64; x++) for (int x = 0; x < 64; x++)
@ -520,9 +523,10 @@ namespace OpenSim.Region.CoreModules.World.Land
} }
} }
m_scene.EventManager.TriggerLandObjectRemoved(m_landList[local_id].LandData.GlobalID); id = m_landList[local_id].LandData.GlobalID;
m_landList.Remove(local_id); m_landList.Remove(local_id);
} }
m_scene.EventManager.TriggerLandObjectRemoved(id);
} }
private void performFinalLandJoin(ILandObject master, ILandObject slave) private void performFinalLandJoin(ILandObject master, ILandObject slave)

View File

@ -122,12 +122,13 @@ namespace OpenSim.Region.Framework.Scenes
public bool InventoryDeQueueAndDelete() public bool InventoryDeQueueAndDelete()
{ {
DeleteToInventoryHolder x = null; DeleteToInventoryHolder x = null;
int left = 0;
try try
{ {
lock (m_inventoryDeletes) lock (m_inventoryDeletes)
{ {
int left = m_inventoryDeletes.Count; left = m_inventoryDeletes.Count;
if (left > 0) if (left > 0)
{ {
x = m_inventoryDeletes.Dequeue(); x = m_inventoryDeletes.Dequeue();
@ -136,7 +137,11 @@ namespace OpenSim.Region.Framework.Scenes
m_inventoryDeletes.Enqueue(x); m_inventoryDeletes.Enqueue(x);
return true; return true;
} }
}
}
if (left > 0)
{
m_log.DebugFormat( m_log.DebugFormat(
"[SCENE]: Sending object to user's inventory, {0} item(s) remaining.", left); "[SCENE]: Sending object to user's inventory, {0} item(s) remaining.", left);
@ -154,7 +159,6 @@ namespace OpenSim.Region.Framework.Scenes
return true; return true;
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
// We can't put the object group details in here since the root part may have disappeared (which is where these sit). // We can't put the object group details in here since the root part may have disappeared (which is where these sit).

View File

@ -297,33 +297,43 @@ namespace OpenSim.Region.Framework.Scenes
sceneObject.AttachToScene(m_parentScene); sceneObject.AttachToScene(m_parentScene);
List<SceneObjectPart> parts = null;
bool found = false;
lock (sceneObject) lock (sceneObject)
{ {
if (!Entities.ContainsKey(sceneObject.UUID)) if (!Entities.ContainsKey(sceneObject.UUID))
{ {
found = true;
Entities.Add(sceneObject); Entities.Add(sceneObject);
m_numPrim += sceneObject.Children.Count; m_numPrim += sceneObject.Children.Count;
if (attachToBackup) if (attachToBackup)
sceneObject.AttachToBackup(); sceneObject.AttachToBackup();
if (OnObjectCreate != null) parts = new List<SceneObjectPart>(sceneObject.Children.Values);
OnObjectCreate(sceneObject);
}
}
if (found)
{
lock (m_dictionary_lock) lock (m_dictionary_lock)
{ {
SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject;
SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject; SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject;
foreach (SceneObjectPart part in sceneObject.Children.Values) foreach (SceneObjectPart part in parts)
{ {
SceneObjectGroupsByFullID[part.UUID] = sceneObject; SceneObjectGroupsByFullID[part.UUID] = sceneObject;
SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; SceneObjectGroupsByLocalID[part.LocalId] = sceneObject;
} }
} }
if (OnObjectCreate != null)
OnObjectCreate(sceneObject);
return true; return true;
} }
}
return false; return false;
} }