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
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