From 0f9ca1d106520db6ec15fbea8bf03574c5dd2ce6 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Sat, 5 Sep 2015 10:48:39 +0300 Subject: [PATCH] Fix data race in Capacity/Count of NetQueue. --- Lidgren.Network/NetQueue.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Lidgren.Network/NetQueue.cs b/Lidgren.Network/NetQueue.cs index 475bc37..25a015b 100644 --- a/Lidgren.Network/NetQueue.cs +++ b/Lidgren.Network/NetQueue.cs @@ -56,12 +56,29 @@ namespace Lidgren.Network /// /// Gets the number of items in the queue /// - public int Count { get { return m_size; } } + public int Count { + get + { + m_lock.EnterReadLock(); + int count = m_size; + m_lock.ExitReadLock(); + return count; + } + } /// /// Gets the current capacity for the queue /// - public int Capacity { get { return m_items.Length; } } + public int Capacity + { + get + { + m_lock.EnterReadLock(); + int capacity = m_items.Length; + m_lock.ExitReadLock(); + return capacity; + } + } /// /// NetQueue constructor