fawkes::ReadWriteLock Class Reference
[Multi-Threading tools, Fawkes Core Library]
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. | |
| virtual | ~ReadWriteLock () |
| Destructor. | |
| void | lock_for_read () |
| Aquire a reader lock. | |
| void | lock_for_write () |
| Aquire a writer lock. | |
| bool | try_lock_for_read () |
| Tries to aquire a reader lock. | |
| bool | try_lock_for_write () |
| Tries to aquire a writer lock. | |
| void | unlock () |
| Release the lock. | |
Detailed Description
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.
- See also:
- example_rwlock.cpp
Definition at line 32 of file read_write_lock.h.
Member Enumeration Documentation
The policy to use for the read/write lock.
- Enumerator:
Definition at line 38 of file read_write_lock.h.
Constructor & Destructor Documentation
| fawkes::ReadWriteLock::ReadWriteLock | ( | ReadWriteLockPolicy | policy = RWLockPolicyPreferWriter |
) |
Constructor.
- Parameters:
-
policy The read/write lock policy to use. The default is to prefer writers.
Definition at line 60 of file read_write_lock.cpp.
References RWLockPolicyPreferReader, and RWLockPolicyPreferWriter.
| fawkes::ReadWriteLock::~ReadWriteLock | ( | ) | [virtual] |
Member Function Documentation
| 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 fawkes::Interface::read().
| 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 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.
- Returns:
- true, if the lock could be aquired, false otherwise.
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.
- Returns:
- true, if the lock has been aquired, false otherwise.
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 fawkes::Interface::read(), fawkes::Interface::set_validity(), and fawkes::Interface::write().
The documentation for this class was generated from the following files:
- src/libs/core/threading/read_write_lock.h
- src/libs/core/threading/read_write_lock.cpp

