C# 클래스 Roslyn.Utilities.NonReentrantLock

A lightweight mutual exclusion object which supports waiting with cancellation and prevents recursion (i.e. you may not call Wait if you already hold the lock)

The NonReentrantLock provides a lightweight mutual exclusion class that doesn't use Windows kernel synchronization primitives.

The implementation is distilled from the workings of T:System.Threading.SemaphoreSlim The basic idea is that we use a regular sync object (Monitor.Enter/Exit) to guard the setting of an 'owning thread' field. If, during the Wait, we find the lock is held by someone else then we register a cancellation callback and enter a "Monitor.Wait" loop. If the cancellation callback fires, then it "pulses" all the waiters to wake them up and check for cancellation. Waiters are also "pulsed" when leaving the lock.

All public members of NonReentrantLock are thread-safe and may be used concurrently from multiple threads.

파일 보기 프로젝트 열기: Runt-Editor/Runt 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
Factory Func

Private Properties

프로퍼티 타입 설명
CancellationTokenCanceledEventHandler void
ReleaseOwnership void
TakeOwnership void

공개 메소드들

메소드 설명
AssertHasLock ( ) : void

Throw an exception if the lock is not held by the calling thread.

LockHeldByMe ( ) : bool

Determine if the lock is currently held by the calling thread.

NonReentrantLock ( bool useThisInstanceForSynchronization = false ) : System

Constructor.

Release ( ) : void

Exit the mutual exclusion.

The calling thread must currently hold the lock.

Wait ( CancellationToken cancellationToken = default(CancellationToken) ) : void

Blocks the current thread until it can enter the NonReentrantLock, while observing a T:System.Threading.CancellationToken.

Recursive locking is not supported. i.e. A thread may not call Wait successfully twice without an intervening Release.

비공개 메소드들

메소드 설명
CancellationTokenCanceledEventHandler ( object obj ) : void

Callback executed when a cancellation token is canceled during a Wait.

ReleaseOwnership ( ) : void

Release ownership of the lock. The lock must already be held by the calling thread.

TakeOwnership ( ) : void

Take ownership of the lock (by the calling thread). The lock may not already be held by any other code.

메소드 상세

AssertHasLock() 공개 메소드

Throw an exception if the lock is not held by the calling thread.
The lock is not currently held by the calling thread.
public AssertHasLock ( ) : void
리턴 void

LockHeldByMe() 공개 메소드

Determine if the lock is currently held by the calling thread.
public LockHeldByMe ( ) : bool
리턴 bool

NonReentrantLock() 공개 메소드

Constructor.
public NonReentrantLock ( bool useThisInstanceForSynchronization = false ) : System
useThisInstanceForSynchronization bool If false (the default), then the class /// allocates an internal object to be used as a sync lock. /// If true, then the sync lock object will be the NonReentrantLock instance itself. This /// saves an allocation but a client may not safely further use this instance in a call to /// Monitor.Enter/Exit or in a "lock" statement. ///
리턴 System

Release() 공개 메소드

Exit the mutual exclusion.
The calling thread must currently hold the lock.
The lock is not currently held by the calling thread.
public Release ( ) : void
리턴 void

Wait() 공개 메소드

Blocks the current thread until it can enter the NonReentrantLock, while observing a T:System.Threading.CancellationToken.
Recursive locking is not supported. i.e. A thread may not call Wait successfully twice without an intervening Release.
was /// canceled. The caller already holds the lock
public Wait ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The token to /// observe.
리턴 void

프로퍼티 상세

Factory 공개적으로 정적으로 프로퍼티

Shared factory for use in lazy initialization.
public static Func Factory
리턴 Func