mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Pull ConcurrentList<T> from ArchiBot
Previous implementation of ConcurrentSortedHashSet was prone to deadlocks and very suboptimal, on top of no guarantee to do what it claimed to.
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Collections {
|
||||
@@ -30,22 +29,20 @@ namespace ArchiSteamFarm.Collections {
|
||||
public T Current => Enumerator.Current;
|
||||
|
||||
private readonly IEnumerator<T> Enumerator;
|
||||
private readonly SemaphoreSlim Semaphore;
|
||||
private readonly IDisposable Lock;
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] SemaphoreSlim semaphore) {
|
||||
if ((collection == null) || (semaphore == null)) {
|
||||
throw new ArgumentNullException(nameof(collection) + " || " + nameof(semaphore));
|
||||
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] IDisposable @lock) {
|
||||
if ((collection == null) || (@lock == null)) {
|
||||
throw new ArgumentNullException(nameof(collection) + " || " + nameof(@lock));
|
||||
}
|
||||
|
||||
Semaphore = semaphore;
|
||||
semaphore.Wait();
|
||||
|
||||
Lock = @lock;
|
||||
Enumerator = collection.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Dispose() => Semaphore.Release();
|
||||
public void Dispose() => Lock.Dispose();
|
||||
public bool MoveNext() => Enumerator.MoveNext();
|
||||
public void Reset() => Enumerator.Reset();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user