Fawkes API
Fawkes Development Version
|
Read/write lock to allow multiple readers but only a single writer on the resource at a time. More...
#include <core/threading/read_write_lock.h>
Public Types | |
enum | ReadWriteLockPolicy { RWLockPolicyPreferWriter, RWLockPolicyPreferReader } |
The policy to use for the read/write lock. More... | |
Public Member Functions | |
ReadWriteLock (ReadWriteLockPolicy policy=RWLockPolicyPreferWriter) | |
Constructor. More... | |
virtual | ~ReadWriteLock () |
Destructor. More... | |
void | lock_for_read () |
Aquire a reader lock. More... | |
void | lock_for_write () |
Aquire a writer lock. More... | |
bool | try_lock_for_read () |
Tries to aquire a reader lock. More... | |
bool | try_lock_for_write () |
Tries to aquire a writer lock. More... | |
void | unlock () |
Release the lock. More... | |
Read/write lock to allow multiple readers but only a single writer on the resource at a time.
This can be used if you have a value that only a few writers modify but several readers use. In this case the readers can read all at the same time as long as there is no writer modifying the value.
Definition at line 32 of file read_write_lock.h.
The policy to use for the read/write lock.
Definition at line 38 of file read_write_lock.h.
fawkes::ReadWriteLock::ReadWriteLock | ( | ReadWriteLockPolicy | policy = RWLockPolicyPreferWriter | ) |
Constructor.
policy | The read/write lock policy to use. The default is to prefer writers. |
Definition at line 60 of file read_write_lock.cpp.
|
virtual |
Destructor.
Definition at line 85 of file read_write_lock.cpp.
void fawkes::ReadWriteLock::lock_for_read | ( | ) |
Aquire a reader lock.
This will aquire the lock for reading. Multiple readers can aquire the lock at the same time. But never when a writer has the lock. This method will block until the lock has been aquired.
Definition at line 98 of file read_write_lock.cpp.
Referenced by PclViewerTransferThread::lock_for_read(), fawkes::ScopedRWLock::relock(), and fawkes::ScopedRWLock::ScopedRWLock().
void fawkes::ReadWriteLock::lock_for_write | ( | ) |
Aquire a writer lock.
This will aquire the lock for writing. Only a single writer at a time will be allowed to aquire the lock. This method will block until the lock has been aquired.
Definition at line 110 of file read_write_lock.cpp.
Referenced by PclViewerTransferThread::loop(), fawkes::ScopedRWLock::relock(), and fawkes::ScopedRWLock::ScopedRWLock().
bool fawkes::ReadWriteLock::try_lock_for_read | ( | ) |
Tries to aquire a reader lock.
This will try to aquire the lock for reading. This will succeed if no writer has aquired the lock already. Multiple readers may aquire the lock.
Definition at line 123 of file read_write_lock.cpp.
bool fawkes::ReadWriteLock::try_lock_for_write | ( | ) |
Tries to aquire a writer lock.
This will try to aquire the lock for writing. This will succeed if the read/write lock is currently unlocked. No other threads may hold this lock at the same time. Neither for writing nor for reading.
Definition at line 136 of file read_write_lock.cpp.
void fawkes::ReadWriteLock::unlock | ( | ) |
Release the lock.
Releases the lock, no matter whether it was locked for reading or writing.
Definition at line 146 of file read_write_lock.cpp.
Referenced by PclViewerTransferThread::loop(), PclViewerTransferThread::unlock(), fawkes::ScopedRWLock::unlock(), and fawkes::ScopedRWLock::~ScopedRWLock().