diff options
Diffstat (limited to 'boost/log/detail/locks.hpp')
-rw-r--r-- | boost/log/detail/locks.hpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/boost/log/detail/locks.hpp b/boost/log/detail/locks.hpp index 99bc7e17f9..224d8e59bb 100644 --- a/boost/log/detail/locks.hpp +++ b/boost/log/detail/locks.hpp @@ -32,6 +32,8 @@ namespace boost { template< typename > class lock_guard; template< typename > +class shared_lock_guard; +template< typename > class shared_lock; template< typename > class upgrade_lock; @@ -92,6 +94,25 @@ struct is_shared_lockable enum value_t { value = sizeof(check_shared_lockable((MutexT*)NULL)) == sizeof(true_type) }; }; +//! A scope guard that automatically unlocks the mutex on destruction +template< typename MutexT > +struct exclusive_auto_unlocker +{ + explicit exclusive_auto_unlocker(MutexT& m) BOOST_NOEXCEPT : m_Mutex(m) + { + } + ~exclusive_auto_unlocker() + { + m_Mutex.unlock(); + } + + BOOST_DELETED_FUNCTION(exclusive_auto_unlocker(exclusive_auto_unlocker const&)) + BOOST_DELETED_FUNCTION(exclusive_auto_unlocker& operator= (exclusive_auto_unlocker const&)) + +protected: + MutexT& m_Mutex; +}; + //! An analogue to the minimalistic \c lock_guard template. Defined here to avoid including Boost.Thread. template< typename MutexT > struct exclusive_lock_guard @@ -105,9 +126,8 @@ struct exclusive_lock_guard m_Mutex.unlock(); } -private: - exclusive_lock_guard(exclusive_lock_guard const&); - exclusive_lock_guard& operator= (exclusive_lock_guard const&); + BOOST_DELETED_FUNCTION(exclusive_lock_guard(exclusive_lock_guard const&)) + BOOST_DELETED_FUNCTION(exclusive_lock_guard& operator= (exclusive_lock_guard const&)) private: MutexT& m_Mutex; @@ -126,9 +146,8 @@ struct shared_lock_guard m_Mutex.unlock_shared(); } -private: - shared_lock_guard(shared_lock_guard const&); - shared_lock_guard& operator= (shared_lock_guard const&); + BOOST_DELETED_FUNCTION(shared_lock_guard(shared_lock_guard const&)) + BOOST_DELETED_FUNCTION(shared_lock_guard& operator= (shared_lock_guard const&)) private: MutexT& m_Mutex; |