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

Read-write synchronization object. More...

#include <base/concurrency/ReadWriteLock.h>

Inherits Resource, and Lock.

Public Types

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

Public Member Functions

 ReadWriteLock ()
 
void exclusiveLock () const
 
bool tryExclusiveLock () const
 
void sharedLock () const
 
bool trySharedLock () const
 
void releaseLock () const
 
 ~ReadWriteLock ()
 
- 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

Read-write synchronization object.

The ReadWriteLock class implements a read-write lock for optimal reader performance on systems which have rwlock support and reverts to a simple mutex for those that do not. Please note that the lock/unlock mechanism is considered a non-modifying property of a class.

See also
MutualExclusion Lock
Version
1.5

Constructor & Destructor Documentation

◆ ReadWriteLock()

ReadWriteLock::ReadWriteLock ( )

Initializes a read-write lock in the unlocked state. Raises ResourceException if unable to initialize the object.

◆ ~ReadWriteLock()

ReadWriteLock::~ReadWriteLock ( )

Destroys the read-write lock object. The lock must be in the unlocked state prior to destruction. Raises ReadWriteLockException on failure.

Member Function Documentation

◆ exclusiveLock()

void ReadWriteLock::exclusiveLock ( ) const
virtual

Acquires an exclusive lock (write-lock) on the read-write lock. The calling thread acquires the lock if no other thread (reader or writer) currently holds the lock. Otherwise, the thread blocks until the lock can be acquired. Results are undefined if the calling thread holds the read-write lock. Raises ReadWriteLockException on failure.

Implements Lock.

◆ releaseLock()

void ReadWriteLock::releaseLock ( ) const
virtual

This method unlocks the read-write lock. Results are undefines if the calling thread does not hold the lock. Raises the exception ReadWriteLockException on failure.

Implements Lock.

◆ sharedLock()

void ReadWriteLock::sharedLock ( ) const
virtual

Acquires a shared lock (read-lock) on the read-write lock. The calling thread blocks until the lock can be acquired. Results are undefined if the calling thread already holds a lock. Raises the exception ReadWriteLockException on failure.

Implements Lock.

◆ tryExclusiveLock()

bool ReadWriteLock::tryExclusiveLock ( ) const
virtual

Attempts to acquire an exclusive lock on the read-write lock. Raises the exception ReadWriteLockException on failure.

Returns
True if the exclusive lock was successfully acquired.

Implements Lock.

◆ trySharedLock()

bool ReadWriteLock::trySharedLock ( ) const
virtual

Attempts to acquire a shared lock on the read-write lock. Raises the exception ReadWriteLockException on failure.

Returns
True if the shared lock was successfully acquired.

Implements Lock.