Add release methods to Lock wrappers
authorScott Cantor <cantor.2@osu.edu>
Wed, 4 Jan 2012 22:38:00 +0000 (22:38 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 4 Jan 2012 22:38:00 +0000 (22:38 +0000)
xmltooling/util/Threads.h

index 63e4c54..191cb15 100644 (file)
@@ -327,13 +327,24 @@ namespace xmltooling
         }
 
         /**
-         * Unlocks the wrapped mutex.
+         * Unlocks the wrapped mutex, if any.
          */
         ~Lock() {
             if (mutex)
                 mutex->unlock();
         }
 
+        /**
+         * Releases control of the original Mutex and returns it without unlocking it.
+         *
+         * @return the original, locked Mutex
+         */
+        Mutex* release() {
+            Mutex* ret = mutex;
+            mutex = nullptr;
+            return ret;
+        }
+
     private:
         Mutex* mutex;
     };
@@ -378,13 +389,24 @@ namespace xmltooling
         }
 
         /**
-         * Unlocks the wrapped shared lock.
+         * Unlocks the wrapped shared lock, if any.
          */
         ~SharedLock() {
             if (rwlock)
                 rwlock->unlock();
         }
 
+        /**
+         * Releases control of the original shared lock and returns it without unlocking it.
+         *
+         * @return the original shared lock
+         */
+        RWLock* release() {
+            RWLock* ret = rwlock;
+            rwlock = nullptr;
+            return ret;
+        }
+
     private:
         RWLock* rwlock;
     };