From 839c1cdcc4e9ce410636becb5b81190463dec5bf Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 24 Sep 2011 01:10:23 +0100 Subject: Improve locking when access queue in EventQueueGetModule --- .../Linden/Caps/EventQueue/EventQueueGetModule.cs | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index 139d8b8..8d0c7a1 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -179,9 +179,10 @@ namespace OpenSim.Region.ClientStack.Linden { Queue queue = GetQueue(avatarID); if (queue != null) - queue.Enqueue(ev); + lock (queue) + queue.Enqueue(ev); } - catch(NullReferenceException e) + catch (NullReferenceException e) { m_log.Error("[EVENTQUEUE] Caught exception: " + e); return false; @@ -338,12 +339,8 @@ namespace OpenSim.Region.ClientStack.Linden Queue queue = GetQueue(agentID); if (queue != null) lock (queue) - { - if (queue.Count > 0) - return true; - else - return false; - } + return queue.Count > 0; + return false; } @@ -358,8 +355,6 @@ namespace OpenSim.Region.ClientStack.Linden element = queue.Dequeue(); // 15s timeout } - - int thisID = 0; lock (m_ids) thisID = m_ids[pAgentId]; @@ -431,7 +426,10 @@ namespace OpenSim.Region.ClientStack.Linden // } Queue queue = TryGetQueue(agentID); - OSD element = queue.Dequeue(); // 15s timeout + OSD element; + + lock (queue) + element = queue.Dequeue(); // 15s timeout Hashtable responsedata = new Hashtable(); @@ -470,10 +468,14 @@ namespace OpenSim.Region.ClientStack.Linden else { array.Add(element); - while (queue.Count > 0) + + lock (queue) { - array.Add(queue.Dequeue()); - thisID++; + while (queue.Count > 0) + { + array.Add(queue.Dequeue()); + thisID++; + } } } @@ -520,6 +522,7 @@ namespace OpenSim.Region.ClientStack.Linden AvatarID = m_QueueUUIDAvatarMapping[capUUID]; } } + if (AvatarID != UUID.Zero) { return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID)); -- cgit v1.1