-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathFileDistributedLockHandle.cs
More file actions
33 lines (27 loc) · 911 Bytes
/
Copy pathFileDistributedLockHandle.cs
File metadata and controls
33 lines (27 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Medallion.Threading.Internal;
namespace Medallion.Threading.FileSystem;
/// <summary>
/// Implements <see cref="IDistributedSynchronizationHandle"/>
/// </summary>
public sealed class FileDistributedLockHandle : IDistributedSynchronizationHandle
{
private FileStream? _fileStream;
internal FileDistributedLockHandle(FileStream fileStream)
{
this._fileStream = fileStream;
}
CancellationToken IDistributedSynchronizationHandle.HandleLostToken =>
Volatile.Read(ref this._fileStream) != null ? CancellationToken.None : throw this.ObjectDisposed();
/// <summary>
/// Releases the lock
/// </summary>
public void Dispose() => Interlocked.Exchange(ref this._fileStream, null)?.Dispose();
/// <summary>
/// Releases the lock
/// </summary>
public ValueTask DisposeAsync()
{
this.Dispose();
return default;
}
}