From b60354d82e3dc0e219cf08e956c94aa2585c104b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Wed, 2 Oct 2019 22:05:01 -0400 Subject: Move t_rwmutex_reader/writer definitions into mutex.cpp These classes are about to get more complex, so let's move them ahead of time into mutex.cpp. --- src/threads/mutex.cpp | 28 ++++++++++++++++++++++++++++ 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(); }; -- cgit v1.2.3