summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Brière <fbriere@fbriere.net>2019-10-02 22:05:01 -0400
committerFrédéric Brière <fbriere@fbriere.net>2019-10-02 23:21:13 -0400
commitb60354d82e3dc0e219cf08e956c94aa2585c104b (patch)
treefe6420ca921977b9a678d476f983f181f4ddcce3
parent79cc23508006d61172522f4b12db8261e760768b (diff)
downloadtwinkle-b60354d82e3dc0e219cf08e956c94aa2585c104b.tar
twinkle-b60354d82e3dc0e219cf08e956c94aa2585c104b.tar.gz
twinkle-b60354d82e3dc0e219cf08e956c94aa2585c104b.tar.lz
twinkle-b60354d82e3dc0e219cf08e956c94aa2585c104b.tar.xz
twinkle-b60354d82e3dc0e219cf08e956c94aa2585c104b.zip
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.
-rw-r--r--src/threads/mutex.cpp28
-rw-r--r--src/threads/mutex.h20
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();
};