From 54b24af033ddedc2cfe9983de7d2bc35a40ee8dd Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 4 Jan 2012 22:38:00 +0000 Subject: [PATCH] Add release methods to Lock wrappers --- xmltooling/util/Threads.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/xmltooling/util/Threads.h b/xmltooling/util/Threads.h index 63e4c54..191cb15 100644 --- a/xmltooling/util/Threads.h +++ b/xmltooling/util/Threads.h @@ -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; }; -- 2.1.4