#include <VersionRWLock.h>
The writers can always read, but the readers can only read if no writer is writing.
When the reader is reading, the writer can write at the same time. But the writer always update the version after before it write the data. Thus the reaser can check the version before and after read action to check whether the data has been updated.
Public Member Functions | |
VersionRWLock () | |
Constructor the lock. | |
int32 | readVersion () |
Gets read permit and returns the current version. | |
bool | verifyVersion (int32 version) |
verify whether the given version and the current version is the same. | |
void | writeLock () |
Write lock the structure (no readers are alowed) and update the version. | |
void | writeUnLock () |
Write unlock the structure. |
|
Constructor the lock. Defines a read write Lock that will not block the writers. The writers can always read, but the readers can only read if no writer is writing. While the reader is reading, the writer can write at the same time, thus the user must check whether the version is valid after reading. |
|
Gets read permit and returns the current version.
|
|
verify whether the given version and the current version is the same. Returns true if so.
|
|
Write lock the structure (no readers are alowed) and update the version.
|
|
Write unlock the structure. If there are no writers, then wakeup the waiting readers |