ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Methods | Protected Fields | List of all members
SmartLock Class Reference
Inheritance diagram for SmartLock:
[legend]
Collaboration diagram for SmartLock:
[legend]

Class Description


This class extends class ThreadLock, adding functionality to register 'acquirers' of type ThreadLock. Only with the second acquirer added, the lock is activated using ThreadLock.SetSafeness(Safeness.Safe). The goal is to not use a mutex, when such use is not needed. In occasions with very high frequency of acquisition, this can provide a performance benefit.

The following rules apply:

Using nulled acquirers:
Sometimes it is useful to add a null as an acquirer. A sample for this is found and explained with lib.ALIB.StdOutputStreamsLock. If the first acquirer is null, the second should be added in a thread-safe way. This means, the code invoking AddAcquirer needs to care for itself, that this object is not acquired during this process. E.g. it can be done in the bootstrap section of a process, when no parallel threads were started. For further acquirere, such care does not need to be taken. While an acquirer must not be attached twice, 'anonymous' (null) acquirers may. For each anonymous invocation of AddAcquirer, a corresponding call RemoveAcquirer is needed, to get back to Safeness.Unsafe.

Public Methods

 SmartLock ()
 
virtual int AddAcquirer (ThreadLock newAcquirer)
 
int CntAcquirers ()
 
virtual int RemoveAcquirer (ThreadLock acquirerToRemove)
 
- Public Methods inherited from ThreadLock
 ThreadLock (LockMode lockMode=LockMode.Recursive, Safeness safeness=Safeness.Safe)
 
virtual void Acquire ([CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="")
 
int DbgCountAcquirements (Thread thread=null)
 
LockMode GetMode ()
 
Safeness GetSafeness ()
 
virtual void Release ()
 
void SetSafeness (Safeness safeness)
 
override String ToString ()
 
bool WillRelease ()
 

Protected Fields

List< ThreadLockacquirers =new List<ThreadLock>()
 
- Protected Fields inherited from ThreadLock
int cntAcquirements
 
LockMode lockMode
 
Object mutex
 
Thread owner
 
Ticks waitTime =new Ticks()
 

Additional Inherited Members

- Public Fields inherited from ThreadLock
int RecursionWarningThreshold =10
 
int waitWarningTimeLimitInMillis =1000
 

Constructor & Destructor Documentation

◆ SmartLock()

SmartLock ( )
inline

Constructs an SmartLock. Parent ThreadLock is initialized to Unsafe mode.

Member Function Documentation

◆ AddAcquirer()

virtual int AddAcquirer ( ThreadLock  newAcquirer)
inlinevirtual

Adds an acquirer.

Parameters
newAcquirerThe acquirer to add.
Returns
The new number of acquirers set.

Reimplemented in TextLogger.

◆ CntAcquirers()

int CntAcquirers ( )
inline

Returns the number of acquirers. This is for debug and statistics purposes.

Returns
The number of acquirers set.

◆ RemoveAcquirer()

virtual int RemoveAcquirer ( ThreadLock  acquirerToRemove)
inlinevirtual

Removes an acquirer.

Parameters
acquirerToRemoveThe acquirer to remove.
Returns
The new number of acquirers set.

Reimplemented in TextLogger.

Member Data Documentation

◆ acquirers

List<ThreadLock> acquirers =new List<ThreadLock>()
protected

The list of acquirers.


The documentation for this class was generated from the following file: