Misc optimization

This commit is contained in:
Archi
2023-11-10 19:02:03 +01:00
parent 1f4f50591a
commit bde696124b

View File

@@ -30,7 +30,7 @@ using ArchiSteamFarm.Core;
namespace ArchiSteamFarm.Helpers;
internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossProcessSemaphore, IDisposable {
private const ushort SpinLockDelay = 1000; // In milliseconds
private const byte SpinLockDelay = 200; // In milliseconds
private readonly string FilePath;
private readonly SemaphoreSlim LocalSemaphore = new(1, 1);
@@ -125,16 +125,12 @@ internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossP
try {
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds >= int.MaxValue) {
if (stopwatch.ElapsedMilliseconds >= millisecondsTimeout) {
return false;
}
millisecondsTimeout -= (int) stopwatch.ElapsedMilliseconds;
if (millisecondsTimeout <= 0) {
return false;
}
while (true) {
try {
// ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that