Class QueuedSynchronizer<TContext>
Provides low-level infrastructure for writing custom synchronization primitives.
Implements
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public abstract class QueuedSynchronizer<TContext> : QueuedSynchronizer, IDisposable
Type Parameters
Name | Description |
---|---|
TContext | The context to be associated with each suspended caller. |
Constructors
| Edit this page View SourceQueuedSynchronizer(int?)
Initializes a new synchronization primitive.
Declaration
protected QueuedSynchronizer(int? concurrencyLevel)
Parameters
Type | Name | Description |
---|---|---|
int? | concurrencyLevel | The expected number of concurrent flows. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Methods
| Edit this page View SourceAcquireAsync(TContext, CancellationToken)
Implements acquire semantics: attempts to move this object to acquired state asynchronously.
Declaration
protected ValueTask AcquireAsync(TContext context, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context to be passed to CanAcquire(TContext). |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | This object has been disposed. |
AcquireAsync(TContext, TimeSpan, CancellationToken)
Implements acquire semantics: attempts to move this object to acquired state asynchronously.
Declaration
protected ValueTask AcquireAsync(TContext context, TimeSpan timeout, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context to be passed to CanAcquire(TContext). |
TimeSpan | timeout | The time to wait for the acquisition. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | true if acquisition is successful; false if timeout occurred. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The operation cannot be completed within the specified amount of time. |
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | This object has been disposed. |
AcquireCore(TContext)
Modifies the internal state according to acquisition semantics.
Declaration
protected virtual void AcquireCore(TContext context)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context associated with the suspended caller or supplied externally. |
Remarks
By default, this method does nothing.
CanAcquire(TContext)
Tests whether the lock acquisition can be done successfully before calling AcquireCore(TContext).
Declaration
protected abstract bool CanAcquire(TContext context)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context associated with the suspended caller or supplied externally. |
Returns
Type | Description |
---|---|
bool |
Release()
Implements release semantics: attempts to resume the suspended callers.
Declaration
protected void Release()
Remarks
This method doesn't invoke ReleaseCore(TContext) method and trying to resume suspended callers.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This object has been disposed. |
Release(TContext)
Implements release semantics: attempts to resume the suspended callers.
Declaration
protected void Release(TContext context)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The argument to be passed to ReleaseCore(TContext). |
Remarks
This methods invokes
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This object has been disposed. |
ReleaseCore(TContext)
Modifies the internal state according to release semantics.
Declaration
protected virtual void ReleaseCore(TContext context)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context associated with the suspended caller or supplied externally. |
Remarks
This method is called by Release(TContext) method.
TryAcquire(TContext)
Implements acquire semantics: attempts to move this object to acquired state synchronously.
Declaration
protected bool TryAcquire(TContext context)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context to be passed to CanAcquire(TContext). |
Returns
Type | Description |
---|---|
bool | true if this primitive is in acquired state; otherwise, false. |
Remarks
This method invokes CanAcquire(TContext), and if it returns true, invokes AcquireCore(TContext) to modify the internal state.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This object has been disposed. |
TryAcquireAsync(TContext, TimeSpan, CancellationToken)
Implements acquire semantics: attempts to move this object to acquired state asynchronously.
Declaration
protected ValueTask<bool> TryAcquireAsync(TContext context, TimeSpan timeout, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | The context to be passed to CanAcquire(TContext). |
TimeSpan | timeout | The time to wait for the acquisition. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask<bool> | true if acquisition is successful; false if timeout occurred. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | This object has been disposed. |