diff options
author | Frédéric Brière <fbriere@fbriere.net> | 2019-10-02 22:13:56 -0400 |
---|---|---|
committer | Frédéric Brière <fbriere@fbriere.net> | 2019-12-26 12:09:17 -0500 |
commit | 3d126cd9a7f9029e199e9220e2ffa08ac4e23227 (patch) | |
tree | fcb055a4439f1a1e87f8c83ef638c5db0d0788b0 /src/threads | |
parent | b60354d82e3dc0e219cf08e956c94aa2585c104b (diff) | |
download | twinkle-3d126cd9a7f9029e199e9220e2ffa08ac4e23227.tar twinkle-3d126cd9a7f9029e199e9220e2ffa08ac4e23227.tar.gz twinkle-3d126cd9a7f9029e199e9220e2ffa08ac4e23227.tar.lz twinkle-3d126cd9a7f9029e199e9220e2ffa08ac4e23227.tar.xz twinkle-3d126cd9a7f9029e199e9220e2ffa08ac4e23227.zip |
Create t_rwmutex_guard base class
(Doing this ahead of time to simplify the next commit a bit.)
Diffstat (limited to 'src/threads')
-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(); |