Skip to content

Commit

Permalink
Fix regression introduced in previous commit
Browse files Browse the repository at this point in the history
Took the lock for thread safety but never released it
  • Loading branch information
borrrden committed Sep 12, 2018
1 parent 644557e commit 41aa8fe
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/Couchbase.Lite.Shared/Util/ThreadSafeHashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,67 @@ internal sealed class ThreadSafeHashSet<T> : ICollection<T>
public int Count
{
get {
_lock.EnterReadLock();
return _internal.Count;
try {
_lock.EnterReadLock();
return _internal.Count;
} finally {
_lock.ExitReadLock();
}
}
}

public bool IsReadOnly => false;

public void Add(T item)
{
_lock.EnterWriteLock();
_internal.Add(item);
try {
_lock.EnterWriteLock();
_internal.Add(item);
} finally {
_lock.ExitWriteLock();
}
}

public void Clear()
{
_lock.EnterWriteLock();
_internal.Clear();
try {
_lock.EnterWriteLock();
_internal.Clear();
} finally {
_lock.ExitWriteLock();
}
}

public bool Contains(T item)
{
_lock.EnterReadLock();
return _internal.Contains(item);
try {
_lock.EnterReadLock();
return _internal.Contains(item);
} finally {
_lock.ExitReadLock();
}
}

public void CopyTo(T[] array, int arrayIndex)
{
_lock.EnterReadLock();
_internal.CopyTo(array, arrayIndex);
try {
_lock.EnterReadLock();
_internal.CopyTo(array, arrayIndex);
} finally {
_lock.ExitReadLock();
}
}

public IEnumerator<T> GetEnumerator() => new SnapshotEnumerator(this);

public bool Remove(T item)
{
_lock.EnterWriteLock();
return _internal.Remove(item);
try {
_lock.EnterWriteLock();
return _internal.Remove(item);
} finally {
_lock.ExitWriteLock();
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand Down

0 comments on commit 41aa8fe

Please sign in to comment.