summaryrefslogtreecommitdiff
path: root/src/unstable/readwritemutex.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2013-02-26 04:54:45 +0000
committerMike Buland <eichlan@xagasoft.com>2013-02-26 04:54:45 +0000
commit772a6bef0de2dcf0b7d9d596ce86f1def4d1f03e (patch)
treea9e3be8f50309fe06c8c1d01092e6fc0d9c5b82d /src/unstable/readwritemutex.h
parentf342b82c4bf125c7cb478160bf011e571c317726 (diff)
downloadlibbu++-772a6bef0de2dcf0b7d9d596ce86f1def4d1f03e.tar.gz
libbu++-772a6bef0de2dcf0b7d9d596ce86f1def4d1f03e.tar.bz2
libbu++-772a6bef0de2dcf0b7d9d596ce86f1def4d1f03e.tar.xz
libbu++-772a6bef0de2dcf0b7d9d596ce86f1def4d1f03e.zip
Added auto-lock classes to the Bu::ReadWriteMutex, I think I like that type of
encapsulation, at least for the read/write guy. Also started work on a thread-safe wrapper for the standard hash. There is a lot of functionality we just have to leave out in this, it's just too dangerous in a thread-safe class.
Diffstat (limited to '')
-rw-r--r--src/unstable/readwritemutex.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/unstable/readwritemutex.h b/src/unstable/readwritemutex.h
index 8641e3f..eb159ca 100644
--- a/src/unstable/readwritemutex.h
+++ b/src/unstable/readwritemutex.h
@@ -69,6 +69,42 @@ namespace Bu
69 */ 69 */
70 void unlockWrite(); 70 void unlockWrite();
71 71
72 class ReadLocker
73 {
74 public:
75 ReadLocker( ReadWriteMutex &m ) :
76 m( m )
77 {
78 m.lockRead();
79 }
80
81 ~ReadLocker()
82 {
83 m.unlockRead();
84 }
85
86 private:
87 ReadWriteMutex &m;
88 };
89
90 class WriteLocker
91 {
92 public:
93 WriteLocker( ReadWriteMutex &m ) :
94 m( m )
95 {
96 m.lockWrite();
97 }
98
99 ~WriteLocker()
100 {
101 m.unlockWrite();
102 }
103
104 private:
105 ReadWriteMutex &m;
106 };
107
72 private: 108 private:
73 Bu::Mutex mRead; 109 Bu::Mutex mRead;
74 int iCounter; 110 int iCounter;