From e55e2eeb07ab6e1fd2f80310d218243abb336e00 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Tue, 30 Jul 2013 22:11:19 +0200 Subject: [PATCH] Adding missing rwmutex.h --- src/util/rwmutex.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/util/rwmutex.h diff --git a/src/util/rwmutex.h b/src/util/rwmutex.h new file mode 100644 index 000000000..8df8503f3 --- /dev/null +++ b/src/util/rwmutex.h @@ -0,0 +1,73 @@ +#ifndef RWLOCK_H +#define RWLOCK_H +#include + +namespace Darling { + +class RWMutex +{ +public: + RWMutex() + { + pthread_rwlock_init(&m_lock, nullptr); + } + ~RWMutex() + { + pthread_rwlock_destroy(&m_lock); + } + + void rdlock() + { + pthread_rwlock_rdlock(&m_lock); + } + + void wrlock() + { + pthread_rwlock_wrlock(&m_lock); + } + + void unlock() + { + pthread_rwlock_unlock(&m_lock); + } +private: + pthread_rwlock_t m_lock; +}; + +class RWMutexReadLock +{ +public: + RWMutexReadLock(RWMutex& mut) + : m_mutex(mut) + { + m_mutex.rdlock(); + } + + ~RWMutexReadLock() + { + m_mutex.unlock(); + } +private: + RWMutex& m_mutex; +}; + +class RWMutexWriteLock +{ +public: + RWMutexWriteLock(RWMutex& mut) + : m_mutex(mut) + { + m_mutex.wrlock(); + } + + ~RWMutexWriteLock() + { + m_mutex.unlock(); + } +private: + RWMutex& m_mutex; +}; + +} + +#endif -- 2.51.2