9 #ifndef LIBPMEMOBJ_CPP_SHARED_MUTEX_HPP 10 #define LIBPMEMOBJ_CPP_SHARED_MUTEX_HPP 12 #include <libpmemobj/thread.h> 13 #include <libpmemobj/tx_base.h> 44 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
46 1, std::generic_category(),
47 "Persistent shared mutex not from persistent memory.");
49 pmemobj_rwlock_zero(pop, &
plock);
72 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
73 if (
int ret = pmemobj_rwlock_wrlock(pop, &this->
plock))
75 "Failed to lock a shared mutex.")
76 .with_pmemobj_errormsg();
97 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
98 if (
int ret = pmemobj_rwlock_rdlock(pop, &this->
plock))
100 ret, std::system_category(),
101 "Failed to shared lock a shared mutex.");
121 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
122 int ret = pmemobj_rwlock_trywrlock(pop, &this->
plock);
126 else if (ret == EBUSY)
130 "Failed to lock a shared mutex.")
131 .with_pmemobj_errormsg();
153 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
154 int ret = pmemobj_rwlock_tryrdlock(pop, &this->
plock);
158 else if (ret == EBUSY)
162 "Failed to lock a shared mutex.")
163 .with_pmemobj_errormsg();
175 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
176 int ret = pmemobj_rwlock_unlock(pop, &this->
plock);
179 ret, std::system_category(),
180 "Failed to unlock a shared mutex.")
181 .with_pmemobj_errormsg();
215 return TX_PARAM_RWLOCK;
void unlock()
Unlocks the mutex.
Definition: shared_mutex.hpp:173
enum pobj_tx_param lock_type() const noexcept
The type of lock needed for the transaction API.
Definition: shared_mutex.hpp:213
PMEMrwlock plock
A POSIX style PMEM-resident shared_mutex.
Definition: shared_mutex.hpp:230
~shared_mutex()=default
Defaulted destructor.
PMEMrwlock * native_handle_type
Implementation defined handle to the native type.
Definition: shared_mutex.hpp:33
void lock_shared()
Lock the mutex for shared access.
Definition: shared_mutex.hpp:95
void unlock_shared()
Unlocks the mutex.
Definition: shared_mutex.hpp:191
shared_mutex()
Default constructor.
Definition: shared_mutex.hpp:41
Custom lock error class.
Definition: pexceptions.hpp:82
Persistent memory resident shared_mutex implementation.
Definition: shared_mutex.hpp:30
native_handle_type native_handle() noexcept
Access a native handle to this shared mutex.
Definition: shared_mutex.hpp:202
bool try_lock()
Try to lock the mutex for exclusive access, returns regardless if the lock succeeds.
Definition: shared_mutex.hpp:119
Persistent memory namespace.
Definition: allocation_flag.hpp:14
void lock()
Lock the mutex for exclusive access.
Definition: shared_mutex.hpp:70
bool try_lock_shared()
Try to lock the mutex for shared access, returns regardless if the lock succeeds. ...
Definition: shared_mutex.hpp:151
shared_mutex & operator=(const shared_mutex &)=delete
Deleted assignment operator.