#include <SWMRSync.h>
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... |
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.
|
Default constructor.
|
|
Default destructor.
|
|
Init sync mechanism.
|
|
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.
|
|
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. |
|
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.
|
|
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. |