C# Class 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 ,
Afficher le fichier Open project: Microsoft/RTVS Class Usage Examples

Méthodes publiques

Méthode Description
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

Private Methods

Méthode Description
TokenReset ( TokenSource tokenSource, bool setIfLast ) : void
TokenSet ( TokenSource tokenSource ) : void

Method Details

BinaryAsyncLock() public méthode

public BinaryAsyncLock ( bool isSet = false ) : System.Threading
isSet bool
Résultat System.Threading

EnqueueReset() public méthode

public EnqueueReset ( ) : void
Résultat void

ResetAsync() public méthode

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
Résultat Task

WaitAsync() public méthode

public WaitAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task
cancellationToken System.Threading.CancellationToken
Résultat Task