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