mirror of
https://github.com/snltty/linker.git
synced 2025-10-08 10:30:08 +08:00
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Threading;
|
|
|
|
namespace linker.libs
|
|
{
|
|
public sealed class OperatingManager
|
|
{
|
|
private uint operating = 0;
|
|
public bool Operating => operating == 1;
|
|
|
|
public bool StartOperation()
|
|
{
|
|
return Interlocked.CompareExchange(ref operating, 1, 0) == 0;
|
|
}
|
|
public void StopOperation()
|
|
{
|
|
Interlocked.Exchange(ref operating, 0);
|
|
}
|
|
}
|
|
|
|
public sealed class OperatingMultipleManager
|
|
{
|
|
private readonly ConcurrentDictionary<string, bool> dicOperating = new ConcurrentDictionary<string, bool>();
|
|
private readonly ConcurrentDictionary<uint, bool> dicOperating1 = new ConcurrentDictionary<uint, bool>();
|
|
|
|
public bool StartOperation(string key)
|
|
{
|
|
return dicOperating.TryAdd(key, true);
|
|
}
|
|
public void StopOperation(string key)
|
|
{
|
|
dicOperating.TryRemove(key, out _);
|
|
}
|
|
|
|
public bool StartOperation(uint key)
|
|
{
|
|
return dicOperating1.TryAdd(key, true);
|
|
}
|
|
public void StopOperation(uint key)
|
|
{
|
|
dicOperating1.TryRemove(key, out _);
|
|
}
|
|
}
|
|
}
|