Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

nvutil::SWMRSync Class Reference

Single write, multiple read synchronization class. More...

#include <SWMRSync.h>

List of all members.

Public Methods

 SWMRSync (void)
 Default constructor. More...

virtual ~SWMRSync (void)
 Default destructor. More...

NVSG_API bool initialize (const char *name=NULL)
 Init sync mechanism. More...

NVSG_API bool waitToWrite (size_t milliseconds, size_t &status) const
 Wait for write access available. More...

NVSG_API void doneWriting () const
 Signal write/read access available again. More...

NVSG_API bool waitToRead (size_t milliseconds, size_t &status) const
 Wait for read access available. More...

NVSG_API void doneReading () const
 Signal one less reading. More...


Detailed Description

Single write, multiple read synchronization class.

The SWMRSync class is based on the ideas from Jeffrey Richter "Advanced Windows"
We use three handles to kernel synchronize our objects:

m_hMutexNoWriter is used to indicate whether a writer thread has access to the data.
When the mutex is signaled, we know that no writer thread is currently
accessing the data.

m_hEventNoReaders indicates whether any reader threads are currently accessing the data.
If no reader threads are accessing the data, this manual-reset event
object is signaled.

m_hSemNumReaders indicates the number of reader threads that are currently accessing the data.
This semaphore is only used as a counter. If the counter goes to 0
m_hEventMoReaders event can be signaled.


Constructor & Destructor Documentation

nvutil::SWMRSync::SWMRSync void   
 

Default constructor.

virtual nvutil::SWMRSync::~SWMRSync void    [virtual]
 

Default destructor.


Member Function Documentation

NVSG_API bool nvutil::SWMRSync::initialize const char *    name = NULL
 

Init sync mechanism.

Returns:
true - init went fine, false - init went wrong
Parameters:
name  The name of the object. Pass NULL if you do not want to share the object (default).

NVSG_API bool nvutil::SWMRSync::waitToWrite size_t    milliseconds,
size_t &    status
const
 

Wait for write access available.

This function checks the current state of the internal write-synchronization object. If that object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse. The function returns, if either the write-synchronization object is signaled or the time-out interval elapses.

Remarks:
If the write-synchronization object was signaled, the function changes the state of both, the internal write-synchronization object and the internal read-synchronization object to nonsignaled before it returns. The state of both objects remains nonsignaled until the calling thread signals write/read access available through a call to doneWriting.
Returns:
true if the calling thread could gain write access, false otherwise.
Parameters:
milliseconds  Time-out interval in milliseconds.
status  currently ignored

NVSG_API void nvutil::SWMRSync::doneWriting   const
 

Signal write/read access available again.

This function signals both, the internal write-synchronisation object and the internal read-synchronization object, so another thread currently waiting for either write or read access, can be released now.

NVSG_API bool nvutil::SWMRSync::waitToRead size_t    milliseconds,
size_t &    status
const
 

Wait for read access available.

This function checks the current state of the internal read-synchronization object. If that object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse. The function returns, if either the read-synchronization object is signaled or the time-out interval elapses.

Remarks:
If the read-synchronization object was signaled, the function changes the state of the internal write-synchronization object to nonsignaled before it returns, so that threads that subsequently begin waiting for write access, will enter the wait state. On the other hand, the state of the read-synchronization object will not be changed, so if the read-synchronization object was signaled, it remains signaled and threads that subsequently begin waiting for read access, immediately will be released. If the calling thread could gain read access, the syncronization object recognizes one more reader. The state of the write-synchronization object will not earlier change to signaled until all readers finished reading through a call to doneReading.
Returns:
true if the calling thread could gain write access, false otherwise.
Parameters:
milliseconds  Time-out interval in millsecond
status  currently ignored

NVSG_API void nvutil::SWMRSync::doneReading   const
 

Signal one less reading.

Through a call to this function, the synchronization object recognizes one less thread reading. If the number of threads currently reading reaches zero, the function will change the state of the internal write-synchronization object to signaled, so a thread that is currently waiting for write access can be released now.


The documentation for this class was generated from the following file:
Generated on Tue Mar 1 13:20:46 2005 for NVSGSDK by NVIDIA