You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:19:37 UTC

svn commit: r920669 - /incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h

Author: dreiss
Date: Tue Mar  9 05:19:37 2010
New Revision: 920669

URL: http://svn.apache.org/viewvc?rev=920669&view=rev
Log:
cpp: Add enum and constructor to RWGuard to make read/write more visible

Modified:
    incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h

Modified: incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h?rev=920669&r1=920668&r2=920669&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.h Tue Mar  9 05:19:37 2010
@@ -86,15 +86,34 @@ class Guard {
   const Mutex& mutex_;
 };
 
+
+// Can be used as second argument to RWGuard to make code more readable
+// as to whether we're doing acquireRead() or acquireWrite().
+enum RWGuardType {
+  RW_READ = 0,
+  RW_WRITE = 1,
+};
+
+
 class RWGuard {
   public:
-    RWGuard(const ReadWriteMutex& value, bool write = 0) : rw_mutex_(value) {
+    RWGuard(const ReadWriteMutex& value, bool write = false)
+         : rw_mutex_(value) {
       if (write) {
         rw_mutex_.acquireWrite();
       } else {
         rw_mutex_.acquireRead();
       }
     }
+
+    RWGuard(const ReadWriteMutex& value, RWGuardType type)
+         : rw_mutex_(value) {
+      if (type == RW_WRITE) {
+        rw_mutex_.acquireWrite();
+      } else {
+        rw_mutex_.acquireRead();
+      }
+    }
     ~RWGuard() {
       rw_mutex_.release();
     }