wasSharp
/Collections/Specialized/ConcurrentHashSet.cs |
@@ -9,7 +9,6 @@ |
using System.Collections; |
using System.Collections.Generic; |
using System.Threading; |
using System.Linq; |
|
namespace wasSharp.Collections.Specialized |
{ |
@@ -21,11 +20,10 @@ |
} |
} |
|
public class ConcurrentHashSet<T> : IDisposable, ICollection<T>, IEnumerable<T>, ISet<T> |
public class ConcurrentHashSet<T> : IDisposable, ISet<T> |
{ |
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
private readonly HashSet<T> _hashSet = null; |
private IEnumerable<string> enumerable; |
private readonly HashSet<T> _hashSet; |
|
public ConcurrentHashSet() |
{ |
@@ -184,7 +182,11 @@ |
_lock.EnterReadLock(); |
try |
{ |
return _hashSet.GetEnumerator(); |
using (var enumerator = _hashSet.GetEnumerator()) |
{ |
while (enumerator.MoveNext()) |
yield return enumerator.Current; |
} |
} |
finally |
{ |
@@ -197,7 +199,11 @@ |
_lock.EnterReadLock(); |
try |
{ |
return _hashSet.GetEnumerator(); |
using (var enumerator = _hashSet.GetEnumerator()) |
{ |
while (enumerator.MoveNext()) |
yield return enumerator.Current; |
} |
} |
finally |
{ |
@@ -205,13 +211,7 @@ |
} |
} |
|
public bool IsReadOnly |
{ |
get |
{ |
return ((ICollection<T>)_hashSet).IsReadOnly; |
} |
} |
public bool IsReadOnly => ((ICollection<T>)_hashSet).IsReadOnly; |
|
#endregion Implementation of ICollection<T> |
|
@@ -225,12 +225,9 @@ |
|
protected virtual void Dispose(bool disposing) |
{ |
if (disposing) |
{ |
if (_lock != null) |
_lock.Dispose(); |
_hashSet.Clear(); |
} |
if (!disposing) return; |
_lock?.Dispose(); |
_hashSet.Clear(); |
} |
|
~ConcurrentHashSet() |