38 #ifndef PMEMOBJ_SHARED_MUTEX_HPP 39 #define PMEMOBJ_SHARED_MUTEX_HPP 41 #include "libpmemobj/thread.h" 42 #include "libpmemobj/tx_base.h" 73 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
75 "Persistent shared mutex not from " 76 "persistent memory.");
78 pmemobj_rwlock_zero(pop, &
plock);
101 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
102 if (
int ret = pmemobj_rwlock_wrlock(pop, &this->
plock))
126 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
127 if (
int ret = pmemobj_rwlock_rdlock(pop, &this->
plock))
129 "Failed to shared lock a " 150 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
151 int ret = pmemobj_rwlock_trywrlock(pop, &this->
plock);
155 else if (ret == EBUSY)
182 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
183 int ret = pmemobj_rwlock_tryrdlock(pop, &this->
plock);
187 else if (ret == EBUSY)
204 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
205 (void)pmemobj_rwlock_unlock(pop, &this->
plock);
239 return TX_PARAM_RWLOCK;
void unlock()
Unlocks the mutex.
Definition: shared_mutex.hpp:202
enum pobj_tx_param lock_type() const noexcept
The type of lock needed for the transaction API.
Definition: shared_mutex.hpp:237
PMEMrwlock plock
A POSIX style PMEM-resident shared_mutex.
Definition: shared_mutex.hpp:254
~shared_mutex()=default
Defaulted destructor.
PMEMrwlock * native_handle_type
Implementation defined handle to the native type.
Definition: shared_mutex.hpp:62
void lock_shared()
Lock the mutex for shared access.
Definition: shared_mutex.hpp:124
void unlock_shared()
Unlocks the mutex.
Definition: shared_mutex.hpp:215
shared_mutex()
Default constructor.
Definition: shared_mutex.hpp:70
Custom lock error class.
Definition: pexceptions.hpp:74
Persistent memory resident shared_mutex implementation.
Definition: shared_mutex.hpp:59
native_handle_type native_handle() noexcept
Access a native handle to this shared mutex.
Definition: shared_mutex.hpp:226
bool try_lock()
Try to lock the mutex for exclusive access, returns regardless if the lock succeeds.
Definition: shared_mutex.hpp:148
Definition: allocator.hpp:48
void lock()
Lock the mutex for exclusive access.
Definition: shared_mutex.hpp:99
bool try_lock_shared()
Try to lock the mutex for shared access, returns regardless if the lock succeeds. ...
Definition: shared_mutex.hpp:180
shared_mutex & operator=(const shared_mutex &)=delete
Deleted assignment operator.