Gigantic code cleanup

Time to enforce some common file layout, as general mess started to annoying me. Sorry in advance for people using custom forks and having merge conflicts, this will help everybody in long-run
This commit is contained in:
JustArchi
2016-11-24 07:32:16 +01:00
parent 1a49c80bc4
commit df218074ad
65 changed files with 4299 additions and 4356 deletions

View File

@@ -29,15 +29,6 @@ using System.Threading;
namespace ArchiSteamFarm {
internal sealed class ConcurrentHashSet<T> : ICollection<T>, IDisposable {
private readonly HashSet<T> HashSet = new HashSet<T>();
private readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
public bool IsReadOnly => false;
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(HashSet, Lock);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
void ICollection<T>.Add(T item) => Add(item);
public int Count {
get {
Lock.EnterReadLock();
@@ -50,6 +41,11 @@ namespace ArchiSteamFarm {
}
}
public bool IsReadOnly => false;
private readonly HashSet<T> HashSet = new HashSet<T>();
private readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
public void Clear() {
Lock.EnterWriteLock();
@@ -70,18 +66,6 @@ namespace ArchiSteamFarm {
}
}
public bool Remove(T item) {
Lock.EnterWriteLock();
try {
return HashSet.Remove(item);
} finally {
Lock.ExitWriteLock();
}
}
public void Dispose() => Lock.Dispose();
public void CopyTo(T[] array, int arrayIndex) {
Lock.EnterReadLock();
@@ -92,6 +76,23 @@ namespace ArchiSteamFarm {
}
}
public void Dispose() => Lock.Dispose();
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(HashSet, Lock);
public bool Remove(T item) {
Lock.EnterWriteLock();
try {
return HashSet.Remove(item);
} finally {
Lock.ExitWriteLock();
}
}
void ICollection<T>.Add(T item) => Add(item);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
internal void Add(T item) {
Lock.EnterWriteLock();
@@ -102,6 +103,17 @@ namespace ArchiSteamFarm {
}
}
internal void ClearAndTrim() {
Lock.EnterWriteLock();
try {
HashSet.Clear();
HashSet.TrimExcess();
} finally {
Lock.ExitWriteLock();
}
}
internal bool ReplaceIfNeededWith(HashSet<T> items) {
Lock.EnterUpgradeableReadLock();
@@ -133,17 +145,6 @@ namespace ArchiSteamFarm {
}
}
internal void ClearAndTrim() {
Lock.EnterWriteLock();
try {
HashSet.Clear();
HashSet.TrimExcess();
} finally {
Lock.ExitWriteLock();
}
}
internal void TrimExcess() {
Lock.EnterWriteLock();
@@ -154,4 +155,4 @@ namespace ArchiSteamFarm {
}
}
}
}
}