1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-16 21:31:45 +02:00
Files
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Phantom.Utils
Collections
Cryptography
IO
Processes
Runtime
Tasks
Threading
ThreadSafeLinkedList.cs
ThreadSafeStructRef.cs
WaitHandleExtensions.cs
Phantom.Utils.csproj
Phantom.Utils.Actor
Phantom.Utils.Events
Phantom.Utils.Logging
Phantom.Utils.Rpc
Phantom.Utils.Tests
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
Minecraft-Phantom-Panel/Utils/Phantom.Utils/Threading/ThreadSafeStructRef.cs

29 lines
627 B
C#

namespace Phantom.Utils.Threading;
public sealed class ThreadSafeStructRef<T> : IDisposable where T : struct {
private T? value;
private readonly SemaphoreSlim semaphore = new (1, 1);
public async Task<T?> Get(CancellationToken cancellationToken) {
await semaphore.WaitAsync(cancellationToken);
try {
return value;
} finally {
semaphore.Release();
}
}
public async Task Set(T? value, CancellationToken cancellationToken) {
await semaphore.WaitAsync(cancellationToken);
try {
this.value = value;
} finally {
semaphore.Release();
}
}
public void Dispose() {
semaphore.Dispose();
}
}