38 #ifndef LIBPMEMOBJ_CPP_SHARED_MUTEX_HPP
39 #define LIBPMEMOBJ_CPP_SHARED_MUTEX_HPP
41 #include <libpmemobj/thread.h>
42 #include <libpmemobj/tx_base.h>
73 if ((pop = pmemobj_pool_by_ptr(&
plock)) ==
nullptr)
75 1, std::generic_category(),
76 "Persistent shared mutex not from 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))
104 "Failed to lock a shared mutex.")
105 .with_pmemobj_errormsg();
126 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
127 if (
int ret = pmemobj_rwlock_rdlock(pop, &this->
plock))
129 ret, std::system_category(),
130 "Failed to shared lock a shared mutex.");
150 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
151 int ret = pmemobj_rwlock_trywrlock(pop, &this->
plock);
155 else if (ret == EBUSY)
159 "Failed to lock a shared mutex.")
160 .with_pmemobj_errormsg();
182 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
183 int ret = pmemobj_rwlock_tryrdlock(pop, &this->
plock);
187 else if (ret == EBUSY)
191 "Failed to lock a shared mutex.")
192 .with_pmemobj_errormsg();
204 PMEMobjpool *pop = pmemobj_pool_by_ptr(
this);
205 int ret = pmemobj_rwlock_unlock(pop, &this->
plock);
208 ret, std::system_category(),
209 "Failed to unlock a shared mutex.")
210 .with_pmemobj_errormsg();
244 return TX_PARAM_RWLOCK;