From: scantor Date: Wed, 4 Jan 2012 22:38:00 +0000 (+0000) Subject: Add release methods to Lock wrappers X-Git-Tag: 1.5.1~41 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fxmltooling.git;a=commitdiff_plain;h=198460d77636b6b1d7439ae1f39d66ddbe351842 Add release methods to Lock wrappers git-svn-id: https://svn.shibboleth.net/cpp-xmltooling/branches/REL_1@952 de75baf8-a10c-0410-a50a-987c0e22f00f --- 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; };