25 #ifndef INCLUDED_SharedMemoryObjectWithMutex_h_GUID_8A1DE87D_04F9_4689_6CAC_6D8579B0464D
26 #define INCLUDED_SharedMemoryObjectWithMutex_h_GUID_8A1DE87D_04F9_4689_6CAC_6D8579B0464D
32 #include <boost/interprocess/interprocess_fwd.hpp>
33 #include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
34 #include <boost/interprocess/sync/sharable_lock.hpp>
35 #include <boost/interprocess/sync/scoped_lock.hpp>
44 namespace bip = boost::interprocess;
47 typedef bip::interprocess_upgradable_mutex mutex_type;
48 typedef bip::scoped_lock<mutex_type> exclusive_lock_type;
49 typedef bip::sharable_lock<mutex_type> sharable_lock_type;
53 sharable_lock_type getSharableLock() {
54 return sharable_lock_type(getMutex());
56 exclusive_lock_type getExclusiveLock() {
57 return exclusive_lock_type(getMutex());
59 mutex_type &getMutex() {
return m_mutex; }
63 if (!lock || (lock.mutex() != &m_mutex)) {
64 throw std::logic_error(
"Lock passed must be "
65 "exclusively locked and for the "
71 template <
typename LockType>
73 if (!lock || (lock.mutex() != &m_mutex)) {
74 throw std::logic_error(
75 "Lock passed must be "
76 "at least sharably locked and for the "
89 #endif // INCLUDED_SharedMemoryObjectWithMutex_h_GUID_8A1DE87D_04F9_4689_6CAC_6D8579B0464D
void verifyReaderLock(LockType &lock) const
Checks to make sure we at least have a reader (sharable) lock.
void verifyWriterLock(exclusive_lock_type &lock) const
Checks to make sure we have a writer (exclusive) lock.