Base Framework
Public Types | Public Member Functions | List of all members
MutualExclusion Class Reference

Mutual exclusion synchronization object. More...

#include <base/concurrency/MutualExclusion.h>

Inherits Resource, and Lock.

Public Types

typedef ExclusiveSynchronize< MutualExclusionSync
 
- Public Types inherited from Lock
typedef ExclusiveSynchronize< LockSync
 

Public Member Functions

 MutualExclusion ()
 
void exclusiveLock () const
 
bool tryExclusiveLock () const
 
void sharedLock () const
 
bool trySharedLock () const
 
void releaseLock () const
 
 ~MutualExclusion ()
 
- Public Member Functions inherited from Resource
String getDescription () const
 
void setDescription (const String &description)
 
unsigned int getResourceId () const
 
unsigned int getCreatedById () const
 
AnyReference getHandle () const noexcept
 
template<class TYPE >
TYPE & getInternalHandle () const
 
 operator bool () const noexcept
 
- Public Member Functions inherited from Lock
 Lock () noexcept
 
virtual ~Lock ()
 

Additional Inherited Members

- Protected Attributes inherited from Resource
AnyReference handle
 

Detailed Description

Mutual exclusion synchronization object.

This class implements a mutual exclusion object used to protect shared data structures from concurrent modifications, implementing critical sections and monitors. Please note that the lock/unlock mechanism is considered a non-modifying property of a class.

See also
Lock
Version
1.2

Constructor & Destructor Documentation

◆ MutualExclusion()

MutualExclusion::MutualExclusion ( )

Initializes a mutual exclusion object in the unlocked state. Raises ResourceException if unable to initialize the object.

◆ ~MutualExclusion()

MutualExclusion::~MutualExclusion ( )

Destroys the mutual exclusion object. The mutual exclusion must be in the unlocked state prior to destruction. Raises MutualExclusionException on failure.

Member Function Documentation

◆ exclusiveLock()

void MutualExclusion::exclusiveLock ( ) const
virtual

Requests a lock on this mutual exclusion object. The calling thread is suspended if the mutex has been locked by another thread. Does nothing if the calling thread already has a lock on the object. Raises MutualExclusionException on undefined failure.

Implements Lock.

◆ releaseLock()

void MutualExclusion::releaseLock ( ) const
virtual

This method unlocks this mutual exclusion object. The calling thread must have a lock on this mutual exlusion object prior to invocation otherwise the behavior is undefined. Raises MutualExclusionException on failure.

Implements Lock.

◆ sharedLock()

void MutualExclusion::sharedLock ( ) const
inlinevirtual

Requests a lock on this mutual exclusion object. The calling thread is suspended if the mutex has been locked by another thread. Does nothing if the calling thread already has a lock on the object. Raises MutualExclusionException on undefined failure.

Implements Lock.

◆ tryExclusiveLock()

bool MutualExclusion::tryExclusiveLock ( ) const
virtual

Attempts to lock this mutual exclusion object. Raises MutualExclusionException on failure.

Returns
True if the mutual exclusion was locked successfully or already was locked by the calling thread.

Implements Lock.

◆ trySharedLock()

bool MutualExclusion::trySharedLock ( ) const
inlinevirtual

Attempts to lock this mutual exclusion object. Raises MutualExclusionException on failure.

Returns
True if the mutual exclusion was locked successfully or already was locked by the calling thread.

Implements Lock.