Reader/Writer Lock. More...
#include <rrwlock.h>
Public Member Functions | |
RRWLock (void) | |
void | ReadLock (void) |
void | ReadUnLock (void) |
void | WriteLock (void) |
void | WriteUnLock (void) |
virtual | ~RRWLock (void) |
Private Attributes | |
size_t | NbReaders |
size_t | NbWriters |
pthread_mutex_t | Mutex |
pthread_cond_t | Cond |
Detailed Description
Reader/Writer Lock.
The RRWLock class provides a reader/writer lock for synchronising threads that access the same data structure when write operations should only be allowed when no thread is reading some data.
Lets suppose that two functions, Print and Insert, used by two different threads access the same variable (a container for example).
R::RContainer<R::RString,true,true> Cont(20);
RRWLock lock;
void Print(int idx)
{
lock.ReadLock();
std::cout<<*Cont[idx]<<std::endl;
lock.ReadUnLock();
}
{
lock.WriteLock();
Cont.InsertPtr(new R::RString(str));
lock.WriteUnLock();
}
Constructor & Destructor Documentation
RRWLock | ( | void | ) |
Construct the lock.
|
virtual |
Destruct the lock.
Member Function Documentation
void ReadLock | ( | void | ) |
Read locking.
void ReadUnLock | ( | void | ) |
Read unlocking.
void WriteLock | ( | void | ) |
Write locking.
void WriteUnLock | ( | void | ) |
Write unlocking.
Field Documentation
|
private |
Number of readers.
|
private |
Number of readers.
|
private |
Pointer to a mutex structure.
|
private |
Pointer to a conditional variable.