Revert "Remove denepdency on Nito.AsyncEx.Coordination"

This reverts commit e05ea63e08.
This commit is contained in:
JustArchi 2020-04-10 21:19:39 +02:00
parent e05ea63e08
commit 876d275400
3 changed files with 19 additions and 69 deletions

View file

@ -60,6 +60,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="Markdig.Signed" Version="0.18.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />
<PackageReference Include="NLog" Version="4.7.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.1" />
<PackageReference Include="SteamKit2" Version="2.3.0-Beta.1" />

View file

@ -22,7 +22,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Collections {
@ -30,24 +29,22 @@ namespace ArchiSteamFarm.Collections {
public T Current => Enumerator.Current;
private readonly IEnumerator<T> Enumerator;
private readonly ReaderWriterLockSlim Lock;
private readonly IDisposable Lock;
object IEnumerator.Current => Current;
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] ReaderWriterLockSlim @lock) {
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] IDisposable @lock) {
if ((collection == null) || (@lock == null)) {
throw new ArgumentNullException(nameof(collection) + " || " + nameof(@lock));
}
@lock.EnterReadLock();
Lock = @lock;
Enumerator = collection.GetEnumerator();
}
public void Dispose() {
Enumerator.Dispose();
Lock.ExitReadLock();
Lock.Dispose();
}
public bool MoveNext() => Enumerator.MoveNext();

View file

@ -22,7 +22,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Nito.AsyncEx;
namespace ArchiSteamFarm.Collections {
internal sealed class ConcurrentList<T> : IList<T>, IReadOnlyList<T> {
@ -30,125 +30,81 @@ namespace ArchiSteamFarm.Collections {
internal int Count {
get {
Lock.EnterReadLock();
try {
using (Lock.ReaderLock()) {
return BackingCollection.Count;
} finally {
Lock.ExitReadLock();
}
}
}
private readonly List<T> BackingCollection = new List<T>();
private readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
private readonly AsyncReaderWriterLock Lock = new AsyncReaderWriterLock();
int ICollection<T>.Count => Count;
int IReadOnlyCollection<T>.Count => Count;
public T this[int index] {
get {
Lock.EnterReadLock();
try {
using (Lock.ReaderLock()) {
return BackingCollection[index];
} finally {
Lock.ExitReadLock();
}
}
set {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection[index] = value;
} finally {
Lock.ExitWriteLock();
}
}
}
public void Add(T item) {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection.Add(item);
} finally {
Lock.ExitWriteLock();
}
}
public void Clear() {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection.Clear();
} finally {
Lock.ExitWriteLock();
}
}
public bool Contains(T item) {
Lock.EnterReadLock();
try {
using (Lock.ReaderLock()) {
return BackingCollection.Contains(item);
} finally {
Lock.ExitReadLock();
}
}
public void CopyTo(T[] array, int arrayIndex) {
Lock.EnterReadLock();
try {
using (Lock.ReaderLock()) {
BackingCollection.CopyTo(array, arrayIndex);
} finally {
Lock.ExitReadLock();
}
}
[JetBrains.Annotations.NotNull]
[SuppressMessage("ReSharper", "AnnotationRedundancyInHierarchy")]
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(BackingCollection, Lock);
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(BackingCollection, Lock.ReaderLock());
public int IndexOf(T item) {
Lock.EnterReadLock();
try {
using (Lock.ReaderLock()) {
return BackingCollection.IndexOf(item);
} finally {
Lock.ExitReadLock();
}
}
public void Insert(int index, T item) {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection.Insert(index, item);
} finally {
Lock.ExitWriteLock();
}
}
public bool Remove(T item) {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
return BackingCollection.Remove(item);
} finally {
Lock.ExitWriteLock();
}
}
public void RemoveAt(int index) {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection.RemoveAt(index);
} finally {
Lock.ExitWriteLock();
}
}
@ -157,13 +113,9 @@ namespace ArchiSteamFarm.Collections {
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
internal void ReplaceWith([JetBrains.Annotations.NotNull] IEnumerable<T> collection) {
Lock.EnterWriteLock();
try {
using (Lock.WriterLock()) {
BackingCollection.Clear();
BackingCollection.AddRange(collection);
} finally {
Lock.ExitWriteLock();
}
}
}