From 713515db49dacd36fb2559bc73db08dd328ddc18 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Thu, 29 Dec 2011 22:55:08 +0000 Subject: [PATCH] Add scoped_ptr support to Lock wrappers --- configure.ac | 1 + cpp-xmltooling.sln | 2 +- xmltooling/util/Threads.h | 26 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 68688b7..7a2f21b 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,7 @@ BOOST_BIND BOOST_CONVERSION BOOST_LAMBDA BOOST_PTR_CONTAINER +BOOST_SMART_PTR BOOST_STRING_ALGO BOOST_TOKENIZER CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS" diff --git a/cpp-xmltooling.sln b/cpp-xmltooling.sln index 872535b..db674e9 100644 --- a/cpp-xmltooling.sln +++ b/cpp-xmltooling.sln @@ -6,7 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{61BF324D-2 m4\acinclude.m4 = m4\acinclude.m4 m4\acx_pthread.m4 = m4\acx_pthread.m4 m4\ax_create_pkgconfig_info.m4 = m4\ax_create_pkgconfig_info.m4 - ..\cpp-sp-ext\m4\boost.m4 = ..\cpp-sp-ext\m4\boost.m4 + m4\boost.m4 = m4\boost.m4 config_win32.h = config_win32.h configure.ac = configure.ac doxygen.am = doxygen.am diff --git a/xmltooling/util/Threads.h b/xmltooling/util/Threads.h index 5269763..63e4c54 100644 --- a/xmltooling/util/Threads.h +++ b/xmltooling/util/Threads.h @@ -30,6 +30,7 @@ #include #include +#include #include namespace xmltooling @@ -310,7 +311,17 @@ namespace xmltooling * * @param mtx mutex to lock */ - Lock(std::auto_ptr& mtx) : mutex(mtx.get()) { + Lock(const std::auto_ptr& mtx) : mutex(mtx.get()) { + if (mutex) + mutex->lock(); + } + + /** + * Locks and wraps the designated mutex. + * + * @param mtx mutex to lock + */ + Lock(const boost::scoped_ptr& mtx) : mutex(mtx.get()) { if (mutex) mutex->lock(); } @@ -350,7 +361,18 @@ namespace xmltooling * @param lock lock to acquire * @param lockit true if the lock should be acquired here, false if already acquired */ - SharedLock(std::auto_ptr& lock, bool lockit=true) : rwlock(lock.get()) { + SharedLock(const std::auto_ptr& lock, bool lockit=true) : rwlock(lock.get()) { + if (rwlock && lockit) + rwlock->rdlock(); + } + + /** + * Locks and wraps the designated shared lock. + * + * @param lock lock to acquire + * @param lockit true if the lock should be acquired here, false if already acquired + */ + SharedLock(const boost::scoped_ptr& lock, bool lockit=true) : rwlock(lock.get()) { if (rwlock && lockit) rwlock->rdlock(); } -- 2.1.4