itom 1.1.0
|
objects of this class organize a read-write-lock mechanism. This class is mainly used by dataObject. If this object is locked for writing (lockWrite), it can not be used for reading nor writing until the writer released the protection with (unlock). On the other hand, the object can multiply be locked for reading if no write-operation is executed at the same time. More...
#include <readWriteLock.h>
Public Member Functions | |
ReadWriteLock (int lockStatus=0) | |
constructor | |
~ReadWriteLock () | |
deconstructor | |
void | lockRead (int increment=1) |
locks for reading | |
void | lockWrite () |
locks for writing | |
void | unlock () |
unlocks a read or write protection | |
void | _unlock (int value) |
unlocks a read or write protection depending on the given integer value | |
int | getLockStatus () const |
returns the protection state | |
Private Member Functions | |
ReadWriteLock (const ReadWriteLock &) | |
Private Attributes | |
int | nrOfReaders |
int | status |
nrOfReaders (>= 0) | |
bool | writeGelocked |
state (-1 if object is in write mode, 0 if object is idle, else number of readers) | |
pthread_mutex_t | mAtomicOp |
pthread_mutex_t | mReadLock |
critical section for realizing atomic operation blocks | |
pthread_mutex_t | mWriteLock |
critical section for realizing the read lock |
objects of this class organize a read-write-lock mechanism. This class is mainly used by dataObject. If this object is locked for writing (lockWrite), it can not be used for reading nor writing until the writer released the protection with (unlock). On the other hand, the object can multiply be locked for reading if no write-operation is executed at the same time.
ReadWriteLock::ReadWriteLock | ( | int | lockStatus = 0 | ) | [inline] |
constructor
int | lockStatus = 0, should normally be used with the default parameter, else: lockStatus: -1 writeLock, 0 no lock, >0 read lock with given number of readers |
void ReadWriteLock::_unlock | ( | int | value | ) | [inline] |
unlocks a read or write protection depending on the given integer value
int | value (-1 : unlocks write protection, >0 unlocks the given number of reading protections) |
int ReadWriteLock::getLockStatus | ( | ) | const [inline] |
returns the protection state
void ReadWriteLock::lockRead | ( | int | increment = 1 | ) | [inline] |
locks for reading
locks this object for reading. This method waits until the object is not protected by any write operation and then locks it for reading. If other participants are already reading this object, the number of readers variable is just incremented
int | increment, number of new readers |
void ReadWriteLock::lockWrite | ( | ) | [inline] |
locks for writing
locks this object for writing. This method waits until this object is in idle mode and then locks it for one single writing operation.
void ReadWriteLock::unlock | ( | ) | [inline] |
unlocks a read or write protection
If this object is in write-mode, this write-protection is unlocked. Else the number of readers is decremented. The reading-protection is finally unlocked, if no other reader is reading the object.