fix: Removed the OnItemTrimmed event from the ScrollQueue due to deadlocks

This commit is contained in:
Chris Cameron
2020-08-21 12:04:35 -04:00
parent 5ca76f7e7e
commit 49a154ebed
2 changed files with 19 additions and 17 deletions

View File

@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased] ## [Unreleased]
### Removed
- Removed the OnItemTrimmed event from the ScrollQueue due to deadlocks
## [11.1.0] - 2020-05-19 ## [11.1.0] - 2020-05-19
### Added ### Added
- ScrollQueue - Added OnItemTrimmed event - ScrollQueue - Added OnItemTrimmed event

View File

@@ -2,8 +2,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using ICD.Common.Properties; using ICD.Common.Properties;
using ICD.Common.Utils.EventArguments;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.Collections namespace ICD.Common.Utils.Collections
{ {
@@ -17,11 +15,6 @@ namespace ICD.Common.Utils.Collections
private readonly LinkedList<TContents> m_Collection; private readonly LinkedList<TContents> m_Collection;
private int m_MaxSize; private int m_MaxSize;
/// <summary>
/// Raised when an item is trimmed from the end of the queue.
/// </summary>
public event EventHandler<GenericEventArgs<TContents>> OnItemTrimmed;
#region Properties #region Properties
/// <summary> /// <summary>
@@ -38,7 +31,8 @@ namespace ICD.Common.Utils.Collections
m_MaxSize = value; m_MaxSize = value;
Trim(); TContents unused;
Trim(out unused);
} }
} }
@@ -86,11 +80,13 @@ namespace ICD.Common.Utils.Collections
/// Appends the item to the queue, trims old items that exceed max length. /// Appends the item to the queue, trims old items that exceed max length.
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="removed"></param>
/// <returns>Returns true if an item was dequeued.</returns>
[PublicAPI] [PublicAPI]
public void Enqueue(TContents item) public bool Enqueue(TContents item, out TContents removed)
{ {
m_Collection.AddLast(item); m_Collection.AddLast(item);
Trim(); return Trim(out removed);
} }
/// <summary> /// <summary>
@@ -145,14 +141,17 @@ namespace ICD.Common.Utils.Collections
/// <summary> /// <summary>
/// Removes items that fall outside of the max size. /// Removes items that fall outside of the max size.
/// </summary> /// </summary>
private void Trim() private bool Trim(out TContents removed)
{ {
while (Count > MaxSize) removed = default(TContents);
{
TContents removed = m_Collection.First.Value; if (Count <= MaxSize)
m_Collection.RemoveFirst(); return false;
OnItemTrimmed.Raise(this, new GenericEventArgs<TContents>(removed));
} removed = m_Collection.First.Value;
m_Collection.RemoveFirst();
return true;
} }
#endregion #endregion