diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/threads/mutex.cpp | 11 | ||||
-rw-r--r-- | src/threads/mutex.h | 15 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/threads/mutex.cpp b/src/threads/mutex.cpp index 9c6a762..7eaa329 100644 --- a/src/threads/mutex.cpp +++ b/src/threads/mutex.cpp @@ -129,7 +129,13 @@ void t_rwmutex::unlock() // t_rwmutex_guard /////////////////////////// -t_rwmutex_reader::t_rwmutex_reader(t_rwmutex& mutex) : _mutex(mutex) +t_rwmutex_guard::t_rwmutex_guard(t_rwmutex& mutex) : + _mutex(mutex) +{ +} + +t_rwmutex_reader::t_rwmutex_reader(t_rwmutex& mutex) : + t_rwmutex_guard(mutex) { // std::cout << "mtx rd lock " << (void*)&_mutex << std::endl; _mutex.lockRead(); @@ -141,7 +147,8 @@ t_rwmutex_reader::~t_rwmutex_reader() _mutex.unlock(); } -t_rwmutex_writer::t_rwmutex_writer(t_rwmutex& mutex) : _mutex(mutex) +t_rwmutex_writer::t_rwmutex_writer(t_rwmutex& mutex) : + t_rwmutex_guard(mutex) { // std::cout << "mtx wr lock " << (void*)&_mutex << std::endl; _mutex.lockWrite(); diff --git a/src/threads/mutex.h b/src/threads/mutex.h index 15d5181..d757d61 100644 --- a/src/threads/mutex.h +++ b/src/threads/mutex.h @@ -95,17 +95,22 @@ public: void unlock(); }; -class t_rwmutex_reader { -private: +// Base (abstract) class +class t_rwmutex_guard { +protected: t_rwmutex& _mutex; + + // A protected constructor to keep this class abstract + t_rwmutex_guard(t_rwmutex& mutex); +}; + +class t_rwmutex_reader : public t_rwmutex_guard { public: t_rwmutex_reader(t_rwmutex& mutex); ~t_rwmutex_reader(); }; -class t_rwmutex_writer { -private: - t_rwmutex& _mutex; +class t_rwmutex_writer : public t_rwmutex_guard { public: t_rwmutex_writer(t_rwmutex& mutex); ~t_rwmutex_writer(); |