9 #ifndef LIBPMEMOBJ_CPP_MUTEX_HPP
10 #define LIBPMEMOBJ_CPP_MUTEX_HPP
13 #include <libpmemobj/thread.h>
14 #include <libpmemobj/tx_base.h>
44 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
46 1, std::generic_category(),
47 "Persistent mutex not from persistent memory.");
49 pmemobj_mutex_zero(pop, &
plock);
71 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
72 if (
int ret = pmemobj_mutex_lock(pop, &this->
plock))
74 "Failed to lock a mutex.")
75 .with_pmemobj_errormsg();
95 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
96 int ret = pmemobj_mutex_trylock(pop, &this->
plock);
100 else if (ret == EBUSY)
104 "Failed to lock a mutex.")
105 .with_pmemobj_errormsg();
118 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
119 int ret = pmemobj_mutex_unlock(pop, &this->
plock);
122 "Failed to unlock a mutex.")
123 .with_pmemobj_errormsg();
145 return TX_PARAM_MUTEX;
Custom lock error class.
Definition: pexceptions.hpp:100
Persistent memory resident mutex implementation.
Definition: mutex.hpp:31
native_handle_type native_handle() noexcept
Access a native handle to this condition variable.
Definition: mutex.hpp:132
mutex()
Default constructor.
Definition: mutex.hpp:41
enum pobj_tx_param lock_type() const noexcept
The type of lock needed for the transaction API.
Definition: mutex.hpp:143
PMEMmutex * native_handle_type
Implementation defined handle to the native type.
Definition: mutex.hpp:34
void unlock()
Unlocks a previously locked mutex.
Definition: mutex.hpp:116
mutex & operator=(const mutex &)=delete
Deleted assignment operator.
void lock()
Locks the mutex, blocks if already locked.
Definition: mutex.hpp:69
~mutex()=default
Defaulted destructor.
mutex(const mutex &)=delete
Deleted copy constructor.
bool try_lock()
Tries to lock the mutex, returns regardless if the lock succeeds.
Definition: mutex.hpp:93
PMEMmutex plock
A POSIX style PMEM-resident mutex.
Definition: mutex.hpp:160
Persistent memory namespace.
Definition: allocation_flag.hpp:15