From e992ca025571a891333a57012c2cd4419b6581e5 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 6 Oct 2009 15:39:53 -0700 Subject: Rewrote parts of the code that were double-locking different objects. This is about half of the code base reviewed. --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 116 ++++++++++++--------- 1 file changed, 69 insertions(+), 47 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 0052729..fe37a08 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -3122,6 +3122,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP objectData.TextureAnim = textureanim; } + bool doUpdate = false; lock (m_primFullUpdates) { if (m_primFullUpdates.Count == 0) @@ -3130,8 +3131,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_primFullUpdates.Add(objectData); if (m_primFullUpdates.Count >= m_primFullUpdatesPerPacket) - ProcessPrimFullUpdates(this, null); + doUpdate = true; } + if (doUpdate) + ProcessPrimFullUpdates(this, null); } void HandleQueueEmpty(ThrottleOutPacketType queue) @@ -3152,35 +3155,40 @@ namespace OpenSim.Region.ClientStack.LindenUDP void ProcessPrimFullUpdates(object sender, ElapsedEventArgs e) { + bool stopTimer = false; lock (m_primFullUpdates) { if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled) - { - lock (m_primFullUpdateTimer) - m_primFullUpdateTimer.Stop(); - - return; - } + stopTimer = true; + } + if (stopTimer) + { + lock (m_primFullUpdateTimer) + m_primFullUpdateTimer.Stop(); + return; + } - ObjectUpdatePacket outPacket = - (ObjectUpdatePacket)PacketPool.Instance.GetPacket( - PacketType.ObjectUpdate); + ObjectUpdatePacket outPacket = + (ObjectUpdatePacket)PacketPool.Instance.GetPacket( + PacketType.ObjectUpdate); - outPacket.RegionData.RegionHandle = - Scene.RegionInfo.RegionHandle; - outPacket.RegionData.TimeDilation = - (ushort)(Scene.TimeDilation * ushort.MaxValue); + outPacket.RegionData.RegionHandle = + Scene.RegionInfo.RegionHandle; + outPacket.RegionData.TimeDilation = + (ushort)(Scene.TimeDilation * ushort.MaxValue); - int max = m_primFullUpdates.Count; - if (max > m_primFullUpdatesPerPacket) - max = m_primFullUpdatesPerPacket; + int max = m_primFullUpdates.Count; + if (max > m_primFullUpdatesPerPacket) + max = m_primFullUpdatesPerPacket; - int count = 0; - int size = 0; + int count = 0; + int size = 0; - byte[] zerobuffer = new byte[1024]; - byte[] blockbuffer = new byte[1024]; + byte[] zerobuffer = new byte[1024]; + byte[] blockbuffer = new byte[1024]; + lock (m_primFullUpdates) + { for (count = 0 ; count < max ; count++) { int length = 0; @@ -3204,9 +3212,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority); if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled) - lock (m_primFullUpdateTimer) - m_primFullUpdateTimer.Stop(); + stopTimer = true; } + + if (stopTimer) + lock (m_primFullUpdateTimer) + m_primFullUpdateTimer.Stop(); } /// @@ -3225,6 +3236,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, state); + bool doUpdate = false; lock (m_primTerseUpdates) { if (m_primTerseUpdates.Count == 0) @@ -3233,43 +3245,51 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_primTerseUpdates.Add(objectData); if (m_primTerseUpdates.Count >= m_primTerseUpdatesPerPacket) - ProcessPrimTerseUpdates(this, null); + doUpdate = true; } + if (doUpdate) + ProcessPrimTerseUpdates(this, null); } void ProcessPrimTerseUpdates(object sender, ElapsedEventArgs e) { + bool stopTimer = false; lock (m_primTerseUpdates) { if (m_primTerseUpdates.Count == 0) - { - lock (m_primTerseUpdateTimer) - m_primTerseUpdateTimer.Stop(); + stopTimer = true; + } + if (stopTimer) + { + lock (m_primTerseUpdateTimer) + m_primTerseUpdateTimer.Stop(); - return; - } + return; + } - ImprovedTerseObjectUpdatePacket outPacket = - (ImprovedTerseObjectUpdatePacket) - PacketPool.Instance.GetPacket( - PacketType.ImprovedTerseObjectUpdate); + ImprovedTerseObjectUpdatePacket outPacket = + (ImprovedTerseObjectUpdatePacket) + PacketPool.Instance.GetPacket( + PacketType.ImprovedTerseObjectUpdate); - outPacket.RegionData.RegionHandle = - Scene.RegionInfo.RegionHandle; - outPacket.RegionData.TimeDilation = - (ushort)(Scene.TimeDilation * ushort.MaxValue); + outPacket.RegionData.RegionHandle = + Scene.RegionInfo.RegionHandle; + outPacket.RegionData.TimeDilation = + (ushort)(Scene.TimeDilation * ushort.MaxValue); - int max = m_primTerseUpdates.Count; - if (max > m_primTerseUpdatesPerPacket) - max = m_primTerseUpdatesPerPacket; + int max = m_primTerseUpdates.Count; + if (max > m_primTerseUpdatesPerPacket) + max = m_primTerseUpdatesPerPacket; - int count = 0; - int size = 0; + int count = 0; + int size = 0; - byte[] zerobuffer = new byte[1024]; - byte[] blockbuffer = new byte[1024]; + byte[] zerobuffer = 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; m_primTerseUpdates[count].ToBytes(blockbuffer, ref length); @@ -3294,9 +3314,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority); if (m_primTerseUpdates.Count == 0) - lock (m_primTerseUpdateTimer) - m_primTerseUpdateTimer.Stop(); + stopTimer = true; } + if (stopTimer) + lock (m_primTerseUpdateTimer) + m_primTerseUpdateTimer.Stop(); } public void FlushPrimUpdates() -- cgit v1.1