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 31 of file read_write_lock.h.
The policy to use for the read/write lock.
Definition at line 36 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 57 of file read_write_lock.cpp.
References RWLockPolicyPreferReader, and RWLockPolicyPreferWriter.
|
virtual |
Destructor.
Definition at line 81 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 93 of file read_write_lock.cpp.
Referenced by fawkes::Interface::copy_shared_to_buffer(), PclViewerTransferThread::lock_for_read(), fawkes::Interface::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 104 of file read_write_lock.cpp.
Referenced by PclViewerTransferThread::loop(), fawkes::ScopedRWLock::relock(), fawkes::ScopedRWLock::ScopedRWLock(), fawkes::Interface::set_validity(), and fawkes::Interface::write().
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 116 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 128 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 137 of file read_write_lock.cpp.
Referenced by fawkes::Interface::copy_shared_to_buffer(), PclViewerTransferThread::loop(), fawkes::Interface::read(), fawkes::Interface::set_validity(), fawkes::ScopedRWLock::unlock(), PclViewerTransferThread::unlock(), fawkes::Interface::write(), and fawkes::ScopedRWLock::~ScopedRWLock().