[scope lock wrapped for ReadWriteMutex]
authoryunfang <dev-null@apache.org>
Sat, 14 Jul 2007 01:23:05 +0000 (01:23 +0000)
committeryunfang <dev-null@apache.org>
Sat, 14 Jul 2007 01:23:05 +0000 (01:23 +0000)
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

lib/cpp/src/concurrency/Mutex.h

index 7945e05..bb2a606 100644 (file)
@@ -61,6 +61,22 @@ class Guard {
   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