From 198460d77636b6b1d7439ae1f39d66ddbe351842 Mon Sep 17 00:00:00 2001 From: scantor Date: Wed, 4 Jan 2012 22:38:00 +0000 Subject: [PATCH] Add release methods to Lock wrappers git-svn-id: https://svn.shibboleth.net/cpp-xmltooling/branches/REL_1@952 de75baf8-a10c-0410-a50a-987c0e22f00f --- 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