Mark3 Realtime Kernel
Mark3::ReaderWriterLock Class Reference

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...
 

Detailed Description

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.

Member Function Documentation

◆ AcquireReader() [1/2]

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.

◆ AcquireReader() [2/2]

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.

Parameters
u32TimeoutMs_Maximum time to wait (in ms) before the operation is aborted
Returns
true on success, false on timeout

Definition at line 38 of file readerwriter.cpp.

◆ AcquireReader_i()

bool Mark3::ReaderWriterLock::AcquireReader_i ( uint32_t  u32TimeoutMs_)
private

AcquireReader_i Internal helper function for AcquireReaer.

Parameters
u32TimeoutMs_Maximum time to wait (in ms) before the operation is aborted
Returns
true on success, false on timeout

Definition at line 73 of file readerwriter.cpp.

◆ AcquireWriter() [1/2]

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.

◆ AcquireWriter() [2/2]

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.

Parameters
u32TimeoutMs_Maximum time to wait (in ms) before the operation is aborted
Returns
true on success, false on timeout

Definition at line 61 of file readerwriter.cpp.

◆ AcquireWriter_i()

bool Mark3::ReaderWriterLock::AcquireWriter_i ( uint32_t  u32TimeoutMs_)
private

AcquireWriter_i Internal helper function for AcquireWriter.

Parameters
u32TimeoutMs_Maximum time to wait (in ms) before the operation is aborted
Returns
true on success, false on timeout

Definition at line 90 of file readerwriter.cpp.

◆ Init()

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.

◆ operator new()

void* Mark3::ReaderWriterLock::operator new ( size_t  sz,
void *  pv 
)
inline

Definition at line 43 of file readerwriter.h.

◆ ReleaseReader()

void Mark3::ReaderWriterLock::ReleaseReader ( )

ReleaseReader Release a previously-held reader lock.

Definition at line 44 of file readerwriter.cpp.

◆ ReleaseWriter()

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.

Member Data Documentation

◆ m_clGlobalMutex

Mutex Mark3::ReaderWriterLock::m_clGlobalMutex
private

Mutex used to lock the object against concurrent read + write.

Definition at line 116 of file readerwriter.h.

◆ m_clReaderMutex

Mutex Mark3::ReaderWriterLock::m_clReaderMutex
private

Mutex used to lock object for readers.

Definition at line 117 of file readerwriter.h.

◆ m_u8ReadCount

uint8_t Mark3::ReaderWriterLock::m_u8ReadCount
private

Number of concurrent readers.

Definition at line 118 of file readerwriter.h.


The documentation for this class was generated from the following files: