-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathPostgresDistributedReaderWriterLock.IDistributedReaderWriterLock.cs
More file actions
154 lines (142 loc) · 10.7 KB
/
Copy pathPostgresDistributedReaderWriterLock.IDistributedReaderWriterLock.cs
File metadata and controls
154 lines (142 loc) · 10.7 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using Medallion.Threading.Internal;
namespace Medallion.Threading.Postgres;
public partial class PostgresDistributedReaderWriterLock
{
// AUTO-GENERATED
IDistributedSynchronizationHandle? IDistributedReaderWriterLock.TryAcquireReadLock(TimeSpan timeout, CancellationToken cancellationToken) =>
this.TryAcquireReadLock(timeout, cancellationToken);
IDistributedSynchronizationHandle IDistributedReaderWriterLock.AcquireReadLock(TimeSpan? timeout, CancellationToken cancellationToken) =>
this.AcquireReadLock(timeout, cancellationToken);
ValueTask<IDistributedSynchronizationHandle?> IDistributedReaderWriterLock.TryAcquireReadLockAsync(TimeSpan timeout, CancellationToken cancellationToken) =>
this.TryAcquireReadLockAsync(timeout, cancellationToken).Convert(To<IDistributedSynchronizationHandle?>.ValueTask);
ValueTask<IDistributedSynchronizationHandle> IDistributedReaderWriterLock.AcquireReadLockAsync(TimeSpan? timeout, CancellationToken cancellationToken) =>
this.AcquireReadLockAsync(timeout, cancellationToken).Convert(To<IDistributedSynchronizationHandle>.ValueTask);
IDistributedSynchronizationHandle? IDistributedReaderWriterLock.TryAcquireWriteLock(TimeSpan timeout, CancellationToken cancellationToken) =>
this.TryAcquireWriteLock(timeout, cancellationToken);
IDistributedSynchronizationHandle IDistributedReaderWriterLock.AcquireWriteLock(TimeSpan? timeout, CancellationToken cancellationToken) =>
this.AcquireWriteLock(timeout, cancellationToken);
ValueTask<IDistributedSynchronizationHandle?> IDistributedReaderWriterLock.TryAcquireWriteLockAsync(TimeSpan timeout, CancellationToken cancellationToken) =>
this.TryAcquireWriteLockAsync(timeout, cancellationToken).Convert(To<IDistributedSynchronizationHandle?>.ValueTask);
ValueTask<IDistributedSynchronizationHandle> IDistributedReaderWriterLock.AcquireWriteLockAsync(TimeSpan? timeout, CancellationToken cancellationToken) =>
this.AcquireWriteLockAsync(timeout, cancellationToken).Convert(To<IDistributedSynchronizationHandle>.ValueTask);
/// <summary>
/// Attempts to acquire a READ lock synchronously. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
/// <code>
/// using (var handle = myLock.TryAcquireReadLock(...))
/// {
/// if (handle != null) { /* we have the lock! */ }
/// }
/// // dispose releases the lock if we took it
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
public PostgresDistributedReaderWriterLockHandle? TryAcquireReadLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: false);
/// <summary>
/// Acquires a READ lock synchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
/// <code>
/// using (myLock.AcquireReadLock(...))
/// {
/// /* we have the lock! */
/// }
/// // dispose releases the lock
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns>
public PostgresDistributedReaderWriterLockHandle AcquireReadLock(TimeSpan? timeout = null, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: false);
/// <summary>
/// Attempts to acquire a READ lock asynchronously. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
/// <code>
/// await using (var handle = await myLock.TryAcquireReadLockAsync(...))
/// {
/// if (handle != null) { /* we have the lock! */ }
/// }
/// // dispose releases the lock if we took it
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
public ValueTask<PostgresDistributedReaderWriterLockHandle?> TryAcquireReadLockAsync(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
this.As<IInternalDistributedReaderWriterLock<PostgresDistributedReaderWriterLockHandle>>().InternalTryAcquireAsync(timeout, cancellationToken, isWrite: false);
/// <summary>
/// Acquires a READ lock asynchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
/// <code>
/// await using (await myLock.AcquireReadLockAsync(...))
/// {
/// /* we have the lock! */
/// }
/// // dispose releases the lock
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns>
public ValueTask<PostgresDistributedReaderWriterLockHandle> AcquireReadLockAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: false);
/// <summary>
/// Attempts to acquire a WRITE lock synchronously. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
/// <code>
/// using (var handle = myLock.TryAcquireWriteLock(...))
/// {
/// if (handle != null) { /* we have the lock! */ }
/// }
/// // dispose releases the lock if we took it
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
public PostgresDistributedReaderWriterLockHandle? TryAcquireWriteLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: true);
/// <summary>
/// Acquires a WRITE lock synchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
/// <code>
/// using (myLock.AcquireWriteLock(...))
/// {
/// /* we have the lock! */
/// }
/// // dispose releases the lock
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns>
public PostgresDistributedReaderWriterLockHandle AcquireWriteLock(TimeSpan? timeout = null, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: true);
/// <summary>
/// Attempts to acquire a WRITE lock asynchronously. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
/// <code>
/// await using (var handle = await myLock.TryAcquireWriteLockAsync(...))
/// {
/// if (handle != null) { /* we have the lock! */ }
/// }
/// // dispose releases the lock if we took it
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
public ValueTask<PostgresDistributedReaderWriterLockHandle?> TryAcquireWriteLockAsync(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
this.As<IInternalDistributedReaderWriterLock<PostgresDistributedReaderWriterLockHandle>>().InternalTryAcquireAsync(timeout, cancellationToken, isWrite: true);
/// <summary>
/// Acquires a WRITE lock asynchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
/// <code>
/// await using (await myLock.AcquireWriteLockAsync(...))
/// {
/// /* we have the lock! */
/// }
/// // dispose releases the lock
/// </code>
/// </summary>
/// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
/// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
/// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns>
public ValueTask<PostgresDistributedReaderWriterLockHandle> AcquireWriteLockAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) =>
DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: true);
}