[scope lock wrapped for ReadWriteMutex]
Summary:
scope lock wrapped around ReadWriteMutex. It's like Guard but you can specify to use it as a read or write lock.
Reviewed by: boz
Test Plan: used it in AdFinder
Revertible: yes
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665162 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h
index 7945e05..bb2a606 100644
--- a/lib/cpp/src/concurrency/Mutex.h
+++ b/lib/cpp/src/concurrency/Mutex.h
@@ -61,6 +61,22 @@
const Mutex& mutex_;
};
+class RWGuard {
+ public:
+ RWGuard(const ReadWriteMutex& value, bool write = 0) : rw_mutex_(value) {
+ if (write) {
+ rw_mutex_.acquireWrite();
+ } else {
+ rw_mutex_.acquireRead();
+ }
+ }
+ ~RWGuard() {
+ rw_mutex_.release();
+ }
+ private:
+ const ReadWriteMutex rw_mutex_;
+};
+
}}} // facebook::thrift::concurrency