Skip to content

Commit

Permalink
Merge pull request #6 from ShawnLaMountain/main
Browse files Browse the repository at this point in the history
Replaced custom lock 'ReaderWriterNotifyLock' with 'System.Threading.ReaderWriterLockSlim'
  • Loading branch information
ShawnLaMountain authored Feb 21, 2022
2 parents cf5a932 + ecf0311 commit 589e04d
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 423 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
[![CI](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CI.yml/badge.svg)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CI.yml)
[![CD](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml/badge.svg)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml)
[![Nuget](https://img.shields.io/nuget/v/ThunderDesign.Net-PCL.Threading)](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading)
[![License](https://img.shields.io/github/license/ThunderDesign/ThunderDesign.Net-PCL.Threading)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/LICENSE)

Thread-Safe Objects
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using ThunderDesign.Net.Threading.Interfaces;
using ThunderDesign.Net.Threading.Threading;

namespace ThunderDesign.Net.Threading.Collections
{
Expand All @@ -23,14 +22,14 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
{
get
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Comparer;
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
}
Expand All @@ -39,14 +38,14 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
{
get
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Count;
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
}
Expand All @@ -55,14 +54,14 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
{
get
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Keys;
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
}
Expand All @@ -71,14 +70,14 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
{
get
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Values;
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
}
Expand All @@ -87,26 +86,26 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
{
get
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base[key];
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
set
{
_ReaderWriterNotifyLock.EnterWriteLock();
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base[key] = value;
}
finally
{
_ReaderWriterNotifyLock.ExitWriteLock();
_ReaderWriterLockSlim.ExitWriteLock();
}
}
}
Expand All @@ -115,127 +114,127 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
#region methods
public new virtual void Add(TKey key, TValue value)
{
_ReaderWriterNotifyLock.EnterWriteLock();
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.Add(key, value);
}
finally
{
_ReaderWriterNotifyLock.ExitWriteLock();
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new virtual void Clear()
{
_ReaderWriterNotifyLock.EnterWriteLock();
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.Clear();
}
finally
{
_ReaderWriterNotifyLock.ExitWriteLock();
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new bool ContainsKey(TKey key)
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.ContainsKey(key);
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new bool ContainsValue(TValue value)
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.ContainsValue(value);
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new Enumerator GetEnumerator()
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.GetEnumerator();
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}

[System.Security.SecurityCritical] // auto-generated_required
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
base.GetObjectData(info, context);
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}

public override void OnDeserialization(Object sender)
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
base.OnDeserialization(sender);
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new virtual bool Remove(TKey key)
{
bool result = false;
_ReaderWriterNotifyLock.EnterWriteLock();
_ReaderWriterLockSlim.EnterWriteLock();
try
{
result = base.Remove(key);
}
finally
{
_ReaderWriterNotifyLock.ExitWriteLock();
_ReaderWriterLockSlim.ExitWriteLock();
}
return result;
}

public new bool TryGetValue(TKey key, out TValue value)
{
_ReaderWriterNotifyLock.EnterReadLock();
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.TryGetValue(key, out value);
}
finally
{
_ReaderWriterNotifyLock.ExitReadLock();
_ReaderWriterLockSlim.ExitReadLock();
}
}
#endregion

#region variables
protected static readonly ReaderWriterNotifyLock _ReaderWriterNotifyLock = new ReaderWriterNotifyLock();
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

#endregion
}
Expand Down
Loading

0 comments on commit 589e04d

Please sign in to comment.