Mark3 Realtime Kernel
|
The ReaderWriterLock class. This class implements an object that marshalls access to a resource based on the intended usage of the resource. A reader-writer lock permits multiple concurrent read access, or single-writer access to a resource. If the object holds a write lock, other writers, and all readers will block until the writer is finished. If the object holds reader locks, all writers will block until all readers are finished before the first writer can take ownership of the resource. This is based upon lower-level synchronization primatives, and is somewhat more heavyweight than primative synchronization types. More...
#include <readerwriter.h>
Public Member Functions | |
void * | operator new (size_t sz, void *pv) |
void | Init () |
Init Initialize the reader-writer lock before use. Must be called before attempting any other operations on the object. More... | |
void | AcquireReader () |
AcquireReader Acquire the object's reader lock. Multiple concurrent readers are allowed. If the writer lock is currently held, the calling thread will wait until the writer lock is relinquished. More... | |
bool | AcquireReader (uint32_t u32TimeoutMs_) |
AcquireReader Acquire the object's reader lock. Multiple concurrent readers are allowed. If the writer lock is currently held, the calling thread will wait until the writer lock is relinquished. More... | |
void | ReleaseReader () |
ReleaseReader Release a previously-held reader lock. More... | |
void | AcquireWriter () |
AcquireWriter Acquire the writer lock. Only a single writer is allowed to access the object at a time. This will block the currently-runnign thread until all other readers/writers have released their locks. More... | |
bool | AcquireWriter (uint32_t u32TimeoutMs_) |
AcquireWriter Acquire the writer lock. Only a single writer is allowed to access the object at a time. This will block the currently-runnign thread until all other readers/writers have released their locks. More... | |
void | ReleaseWriter () |
ReleaseWriter Release the currently held writer, allowing other readers/writers to access the object. More... | |
Private Member Functions | |
bool | AcquireReader_i (uint32_t u32TimeoutMs_) |
AcquireReader_i Internal helper function for AcquireReaer. More... | |
bool | AcquireWriter_i (uint32_t u32TimeoutMs_) |
AcquireWriter_i Internal helper function for AcquireWriter. More... | |
Private Attributes | |
Mutex | m_clGlobalMutex |
Mutex used to lock the object against concurrent read + write. More... | |
Mutex | m_clReaderMutex |
Mutex used to lock object for readers. More... | |
uint8_t | m_u8ReadCount |
Number of concurrent readers. More... | |
The ReaderWriterLock class. This class implements an object that marshalls access to a resource based on the intended usage of the resource. A reader-writer lock permits multiple concurrent read access, or single-writer access to a resource. If the object holds a write lock, other writers, and all readers will block until the writer is finished. If the object holds reader locks, all writers will block until all readers are finished before the first writer can take ownership of the resource. This is based upon lower-level synchronization primatives, and is somewhat more heavyweight than primative synchronization types.
Definition at line 40 of file readerwriter.h.
void Mark3::ReaderWriterLock::AcquireReader | ( | ) |
AcquireReader Acquire the object's reader lock. Multiple concurrent readers are allowed. If the writer lock is currently held, the calling thread will wait until the writer lock is relinquished.
Definition at line 32 of file readerwriter.cpp.
bool Mark3::ReaderWriterLock::AcquireReader | ( | uint32_t | u32TimeoutMs_ | ) |
AcquireReader Acquire the object's reader lock. Multiple concurrent readers are allowed. If the writer lock is currently held, the calling thread will wait until the writer lock is relinquished.
u32TimeoutMs_ | Maximum time to wait (in ms) before the operation is aborted |
Definition at line 38 of file readerwriter.cpp.
|
private |
AcquireReader_i Internal helper function for AcquireReaer.
u32TimeoutMs_ | Maximum time to wait (in ms) before the operation is aborted |
Definition at line 73 of file readerwriter.cpp.
void Mark3::ReaderWriterLock::AcquireWriter | ( | ) |
AcquireWriter Acquire the writer lock. Only a single writer is allowed to access the object at a time. This will block the currently-runnign thread until all other readers/writers have released their locks.
Definition at line 55 of file readerwriter.cpp.
bool Mark3::ReaderWriterLock::AcquireWriter | ( | uint32_t | u32TimeoutMs_ | ) |
AcquireWriter Acquire the writer lock. Only a single writer is allowed to access the object at a time. This will block the currently-runnign thread until all other readers/writers have released their locks.
u32TimeoutMs_ | Maximum time to wait (in ms) before the operation is aborted |
Definition at line 61 of file readerwriter.cpp.
|
private |
AcquireWriter_i Internal helper function for AcquireWriter.
u32TimeoutMs_ | Maximum time to wait (in ms) before the operation is aborted |
Definition at line 90 of file readerwriter.cpp.
void Mark3::ReaderWriterLock::Init | ( | void | ) |
Init Initialize the reader-writer lock before use. Must be called before attempting any other operations on the object.
Definition at line 24 of file readerwriter.cpp.
|
inline |
Definition at line 43 of file readerwriter.h.
void Mark3::ReaderWriterLock::ReleaseReader | ( | ) |
ReleaseReader Release a previously-held reader lock.
Definition at line 44 of file readerwriter.cpp.
void Mark3::ReaderWriterLock::ReleaseWriter | ( | ) |
ReleaseWriter Release the currently held writer, allowing other readers/writers to access the object.
Definition at line 67 of file readerwriter.cpp.
|
private |
Mutex used to lock the object against concurrent read + write.
Definition at line 116 of file readerwriter.h.
|
private |
Mutex used to lock object for readers.
Definition at line 117 of file readerwriter.h.
|
private |
Number of concurrent readers.
Definition at line 118 of file readerwriter.h.