C# Класс Microsoft.Common.Core.Threading.BinaryAsyncLock

BinaryAsyncLock is a helper primitive that can be used instead of SemaphoreSlim.WaitAsync + double-checked locking
After BinaryAsyncLock is created or reset, the first caller of WaitAsync will immediately get IBinaryAsyncLockToken that is not set. All other callers will either wait until IBinaryAsyncLockToken.Set is called and then will get , or until until IBinaryAsyncLockToken.Reset is called and next awaiting caller will get ,
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
BinaryAsyncLock ( bool isSet = false ) : System.Threading
EnqueueReset ( ) : void
ResetAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task

Creates a task that is completed when lock is in Unset state and no reset waiters are in front of current one and all tokens that were issued prior this one are released

Method tries to replace current tail with the new Reset TokenSource (when its task is completed, lock will be in Unset state), and if it fails, it means that another thread has updated the tail, so method tries again with that new tail. If there is no tail, it is considered that lock is in the Unset state already, but no one has requested a token yet If there is a tail, method tries to set its TokenSource.Next to the new TokenSource, and if it fails, it means that another thread has updated the property or the tail, so method tries again with that new tail. If replacing tail succeeded, method stops adding Set tokens. If there are no unreleased set tokens, new tail task is set to completed.

WaitAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task

Приватные методы

Метод Описание
TokenReset ( TokenSource tokenSource, bool setIfLast ) : void
TokenSet ( TokenSource tokenSource ) : void

Описание методов

BinaryAsyncLock() публичный Метод

public BinaryAsyncLock ( bool isSet = false ) : System.Threading
isSet bool
Результат System.Threading

EnqueueReset() публичный Метод

public EnqueueReset ( ) : void
Результат void

ResetAsync() публичный Метод

Creates a task that is completed when lock is in Unset state and no reset waiters are in front of current one and all tokens that were issued prior this one are released
Method tries to replace current tail with the new Reset TokenSource (when its task is completed, lock will be in Unset state), and if it fails, it means that another thread has updated the tail, so method tries again with that new tail. If there is no tail, it is considered that lock is in the Unset state already, but no one has requested a token yet If there is a tail, method tries to set its TokenSource.Next to the new TokenSource, and if it fails, it means that another thread has updated the property or the tail, so method tries again with that new tail. If replacing tail succeeded, method stops adding Set tokens. If there are no unreleased set tokens, new tail task is set to completed.
public ResetAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task
cancellationToken System.Threading.CancellationToken
Результат Task

WaitAsync() публичный Метод

public WaitAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task
cancellationToken System.Threading.CancellationToken
Результат Task