diff options
-rw-r--r-- | src/threads/mutex.cpp | 28 | ||||
-rw-r--r-- | src/threads/mutex.h | 20 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/threads/mutex.cpp b/src/threads/mutex.cpp index 744cd7b..9c6a762 100644 --- a/src/threads/mutex.cpp +++ b/src/threads/mutex.cpp @@ -124,3 +124,31 @@ void t_rwmutex::unlock() { pthread_rwlock_unlock(&_lock); } + +/////////////////////////// +// t_rwmutex_guard +/////////////////////////// + +t_rwmutex_reader::t_rwmutex_reader(t_rwmutex& mutex) : _mutex(mutex) +{ + // std::cout << "mtx rd lock " << (void*)&_mutex << std::endl; + _mutex.lockRead(); +} + +t_rwmutex_reader::~t_rwmutex_reader() +{ + // std::cout << "mtx rd unlock " << (void*)&_mutex << std::endl; + _mutex.unlock(); +} + +t_rwmutex_writer::t_rwmutex_writer(t_rwmutex& mutex) : _mutex(mutex) +{ + // std::cout << "mtx wr lock " << (void*)&_mutex << std::endl; + _mutex.lockWrite(); +} + +t_rwmutex_writer::~t_rwmutex_writer() +{ + // std::cout << "mtx wr unlock " << (void*)&_mutex << std::endl; + _mutex.unlock(); +} diff --git a/src/threads/mutex.h b/src/threads/mutex.h index 1fc07d1..15d5181 100644 --- a/src/threads/mutex.h +++ b/src/threads/mutex.h @@ -99,28 +99,16 @@ class t_rwmutex_reader { private: t_rwmutex& _mutex; public: - t_rwmutex_reader(t_rwmutex& mutex) : _mutex(mutex) { - // std::cout << "mtx rd lock " << (void*)&_mutex << std::endl; - _mutex.lockRead(); - } - ~t_rwmutex_reader() { - // std::cout << "mtx rd unlock " << (void*)&_mutex << std::endl; - _mutex.unlock(); - } + t_rwmutex_reader(t_rwmutex& mutex); + ~t_rwmutex_reader(); }; class t_rwmutex_writer { private: t_rwmutex& _mutex; public: - t_rwmutex_writer(t_rwmutex& mutex) : _mutex(mutex) { - // std::cout << "mtx wr lock " << (void*)&_mutex << std::endl; - _mutex.lockWrite(); - } - ~t_rwmutex_writer() { - // std::cout << "mtx wr unlock " << (void*)&_mutex << std::endl; - _mutex.unlock(); - } + t_rwmutex_writer(t_rwmutex& mutex); + ~t_rwmutex_writer(); }; |