From c249b0f93bd2a4ff8b633ffd1754b0318093cf7f Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Wed, 11 Oct 2006 08:51:40 +0000 Subject: [PATCH] add ctor with std::pair argument git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@705 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/LockingPtr.h | 15 +++++++++++++++ test/LockingPtr/main.cpp | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/loki/LockingPtr.h b/include/loki/LockingPtr.h index 1627267..a207285 100755 --- a/include/loki/LockingPtr.h +++ b/include/loki/LockingPtr.h @@ -47,6 +47,18 @@ namespace Loki mutex.Lock(); } + typedef typename std::pair Pair; + + /** Constructor locks mutex associated with an object. + @param lockpair a std::pair of pointers to the object and the mutex + */ + LockingPtr( Pair lockpair ) + : pObject_( const_cast< SharedObject * >( lockpair.first ) ), + pMutex_( lockpair.second ) + { + lockpair.second->Lock(); + } + /// Destructor unlocks the mutex. ~LockingPtr() { @@ -91,6 +103,9 @@ namespace Loki // $Log$ +// Revision 1.12 2006/10/11 08:51:40 syntheticpp +// add ctor with std::pair argument +// // Revision 1.11 2006/03/08 18:22:42 syntheticpp // doxygen fixes // diff --git a/test/LockingPtr/main.cpp b/test/LockingPtr/main.cpp index 2608b8b..8cb377b 100755 --- a/test/LockingPtr/main.cpp +++ b/test/LockingPtr/main.cpp @@ -124,6 +124,16 @@ int main () Thread::JoinThreads(threads); Thread::DeleteThreads(threads); + + // test pair ctor + volatile A a; + Loki::Mutex m; + UserLockingPtr::Pair pair(&a,&m); + UserLockingPtr l( pair ); + + ConstUserLockingPtr::Pair cpair(&a,&m); + ConstUserLockingPtr cl( cpair ); + }