Persistent memory resident shared_mutex implementation.
More...
#include <libpmemobj++/shared_mutex.hpp>
Persistent memory resident shared_mutex implementation.
This class is an implementation of a PMEM-resident shared_mutex which mimics in behavior the C++11 std::mutex. This class satisfies all requirements of the SharedMutex and StandardLayoutType concepts. The typical usage would be:
#include <mutex>
void
shared_mutex_example()
{
struct root {
nvobj::shared_mutex pmutex;
};
auto pop = nvobj::pool<root>::create("poolfile", "layout",
PMEMOBJ_MIN_POOL);
proot->pmutex.lock_shared();
std::unique_lock<nvobj::shared_mutex> guard(proot->pmutex);
}
◆ shared_mutex()
pmem::obj::shared_mutex::shared_mutex |
( |
| ) |
|
|
inline |
Default constructor.
- Exceptions
-
◆ lock()
void pmem::obj::shared_mutex::lock |
( |
| ) |
|
|
inline |
Lock the mutex for exclusive access.
If a different thread already locked this mutex, the calling thread will block. If the same thread tries to lock a mutex it already owns, either in exclusive or shared mode, the behavior is undefined.
- Exceptions
-
lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex. |
◆ lock_shared()
void pmem::obj::shared_mutex::lock_shared |
( |
| ) |
|
|
inline |
Lock the mutex for shared access.
If a different thread already locked this mutex for exclusive access, the calling thread will block. If it was locked for shared access by a different thread, the lock will succeed.
The mutex can be locked for shared access multiple times by the same thread. If so, the same number of unlocks must be made to unlock the mutex.
- Exceptions
-
lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex. |
◆ lock_type()
enum pobj_tx_param pmem::obj::shared_mutex::lock_type |
( |
| ) |
const |
|
inlinenoexcept |
The type of lock needed for the transaction API.
- Returns
- TX_PARAM_RWLOCK
◆ native_handle()
Access a native handle to this shared mutex.
- Returns
- a pointer to PMEMmutex.
◆ try_lock()
bool pmem::obj::shared_mutex::try_lock |
( |
| ) |
|
|
inline |
Try to lock the mutex for exclusive access, returns regardless if the lock succeeds.
If the same thread tries to lock a mutex it already owns either in exclusive or shared mode, the behavior is undefined.
- Returns
true
on successful lock acquisition, false
otherwise.
- Exceptions
-
lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex. |
◆ try_lock_shared()
bool pmem::obj::shared_mutex::try_lock_shared |
( |
| ) |
|
|
inline |
Try to lock the mutex for shared access, returns regardless if the lock succeeds.
The mutex can be locked for shared access multiple times by the same thread. If so, the same number of unlocks must be made to unlock the mutex. If the calling thread already owns the mutex in any mode, the behavior is undefined.
- Returns
false
if a different thread already locked the mutex for exclusive access, true
otherwise.
- Exceptions
-
lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex. |
◆ unlock()
void pmem::obj::shared_mutex::unlock |
( |
| ) |
|
|
inline |
Unlocks the mutex.
The mutex must be locked for exclusive access by the calling thread, otherwise results in undefined behavior.
◆ unlock_shared()
void pmem::obj::shared_mutex::unlock_shared |
( |
| ) |
|
|
inline |
Unlocks the mutex.
The mutex must be locked for shared access by the calling thread, otherwise results in undefined behavior.
The documentation for this class was generated from the following file: