Show / Hide Table of Contents

Class QueuedSynchronizer<TContext>

Provides low-level infrastructure for writing custom synchronization primitives.

Inheritance
object
Disposable
QueuedSynchronizer
QueuedSynchronizer<TContext>
Implements
IDisposable
Inherited Members
QueuedSynchronizer.MeasurementTags
QueuedSynchronizer.TrackSuspendedCallers(Func<object>)
QueuedSynchronizer.SetCallerInformation(object)
QueuedSynchronizer.GetSuspendedCallers()
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(bool)
QueuedSynchronizer.Dispose(Exception)
QueuedSynchronizer.DisposeAsyncCore()
QueuedSynchronizer.DisposeAsync()
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

QueuedSynchronizer(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

concurrencyLevel is not null and less than 1.

Methods

| Edit this page View Source

AcquireAsync(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

true if acquisition is allowed; otherwise, false.

| Edit this page View Source

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.

| Edit this page View Source

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 to modify the internal state before resuming all suspended callers.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

Implements

IDisposable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾