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 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 acquirers, 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 ()
 
int addAcquirer (ThreadLock newAcquirer)
 
int cntAcquirers ()
 
int removeAcquirer (ThreadLock acquirerToRemove)
 
- Public Methods inherited from ThreadLock
 ThreadLock ()
 
 ThreadLock (LockMode lockMode)
 
 ThreadLock (LockMode lockMode, Safeness safeness)
 
void acquire ()
 
int dbgCountAcquirements (Thread thread)
 
LockMode getMode ()
 
Safeness getSafeness ()
 
void release ()
 
void setSafeness (Safeness safeness)
 
String toString ()
 
boolean willRelease ()
 

Protected Fields

ArrayList< ThreadLockacquirers = new ArrayList<ThreadLock>()
 
- Protected Fields inherited from ThreadLock
int cntAcquirements
 
boolean createOwnerStackTrace = false
 
LockMode lockMode
 
Object mutex
 
Thread owner
 
Exception ownerException
 
Ticks waitTime = new Ticks()
 

Additional Inherited Members

- Public Fields inherited from ThreadLock
int recursionWarningThreshold = 10
 
int waitWarningTimeLimitInMillis = 1000
 
- Package Access Methods inherited from ThreadLock
void constructor (LockMode lockMode, Safeness safeness)
 

Constructor & Destructor Documentation

◆ SmartLock()

SmartLock ( )

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

Member Function Documentation

◆ addAcquirer()

int addAcquirer ( ThreadLock  newAcquirer)

Adds an acquirer.

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

Reimplemented in TextLogger.

◆ cntAcquirers()

int cntAcquirers ( )

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

Returns
The number of acquirers set.

◆ removeAcquirer()

int removeAcquirer ( ThreadLock  acquirerToRemove)

Removes an acquirer.

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

Reimplemented in TextLogger.

Member Data Documentation

◆ acquirers

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

The list of acquirers.


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