diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-12-23 13:16:26 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-12-23 14:43:26 (GMT) |
commit | 491ddd570a752cf9bda85933bed0c6942e39b1f9 (patch) | |
tree | 10c25c1be8cc08d0497df1dccd56a10fbb30beee /3rdParty/Boost/src/boost/thread/locks.hpp | |
parent | da7d7a0ca71b80281aa9ff2526290b61ccb0cc60 (diff) | |
download | swift-491ddd570a752cf9bda85933bed0c6942e39b1f9.zip swift-491ddd570a752cf9bda85933bed0c6942e39b1f9.tar.bz2 |
Update Boost to 1.52.0.
Change-Id: I1e56bea2600bf2ed9c5b3aba8c4f9d2a0f350e77
Diffstat (limited to '3rdParty/Boost/src/boost/thread/locks.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/thread/locks.hpp | 966 |
1 files changed, 604 insertions, 362 deletions
diff --git a/3rdParty/Boost/src/boost/thread/locks.hpp b/3rdParty/Boost/src/boost/thread/locks.hpp index d23e619..c11c2bd 100644 --- a/3rdParty/Boost/src/boost/thread/locks.hpp +++ b/3rdParty/Boost/src/boost/thread/locks.hpp @@ -2,6 +2,8 @@ // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // (C) Copyright 2007 Anthony Williams +// (C) Copyright 2011-2012 Vicente J. Botet Escriba + #ifndef BOOST_THREAD_LOCKS_HPP #define BOOST_THREAD_LOCKS_HPP #include <boost/thread/detail/config.hpp> @@ -12,6 +14,10 @@ #include <boost/thread/thread_time.hpp> #include <boost/detail/workaround.hpp> #include <boost/type_traits/is_class.hpp> +#ifdef BOOST_THREAD_USES_CHRONO +#include <boost/chrono/time_point.hpp> +#include <boost/chrono/duration.hpp> +#endif #include <boost/config/abi_prefix.hpp> @@ -71,7 +77,7 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value=false); }; - + template<typename T> struct has_member_lock<T,true> { @@ -80,22 +86,22 @@ namespace boost { true_type dummy[2]; }; - + template<typename U,typename V> static true_type has_member(V (U::*)()); template<typename U> static false_type has_member(U); - + BOOST_STATIC_CONSTANT( bool,value=sizeof(has_member_lock<T>::has_member(&T::lock))==sizeof(true_type)); }; - + template<typename T,bool=has_member_called_unlock<T>::value > struct has_member_unlock { BOOST_STATIC_CONSTANT(bool, value=false); }; - + template<typename T> struct has_member_unlock<T,true> { @@ -104,22 +110,22 @@ namespace boost { true_type dummy[2]; }; - + template<typename U,typename V> static true_type has_member(V (U::*)()); template<typename U> static false_type has_member(U); - + BOOST_STATIC_CONSTANT( bool,value=sizeof(has_member_unlock<T>::has_member(&T::unlock))==sizeof(true_type)); }; - + template<typename T,bool=has_member_called_try_lock<T>::value > struct has_member_try_lock { BOOST_STATIC_CONSTANT(bool, value=false); }; - + template<typename T> struct has_member_try_lock<T,true> { @@ -128,18 +134,18 @@ namespace boost { true_type dummy[2]; }; - + template<typename U> static true_type has_member(bool (U::*)()); template<typename U> static false_type has_member(U); - + BOOST_STATIC_CONSTANT( bool,value=sizeof(has_member_try_lock<T>::has_member(&T::try_lock))==sizeof(true_type)); }; } - + template<typename T> struct is_mutex_type @@ -147,7 +153,7 @@ namespace boost BOOST_STATIC_CONSTANT(bool, value = detail::has_member_lock<T>::value && detail::has_member_unlock<T>::value && detail::has_member_try_lock<T>::value); - + }; #else template<typename T> @@ -155,7 +161,7 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value = false); }; -#endif +#endif struct defer_lock_t {}; @@ -163,10 +169,10 @@ namespace boost {}; struct adopt_lock_t {}; - - const defer_lock_t defer_lock={}; - const try_to_lock_t try_to_lock={}; - const adopt_lock_t adopt_lock={}; + + BOOST_CONSTEXPR_OR_CONST defer_lock_t defer_lock={}; + BOOST_CONSTEXPR_OR_CONST try_to_lock_t try_to_lock={}; + BOOST_CONSTEXPR_OR_CONST adopt_lock_t adopt_lock={}; template<typename Mutex> class shared_lock; @@ -182,7 +188,7 @@ namespace boost template<typename Mutex> class try_lock_wrapper; } - + #ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES template<typename T> struct is_mutex_type<unique_lock<T> > @@ -201,7 +207,7 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value = true); }; - + template<typename T> struct is_mutex_type<detail::try_lock_wrapper<T> > { @@ -213,7 +219,7 @@ namespace boost class recursive_mutex; class recursive_timed_mutex; class shared_mutex; - + template<> struct is_mutex_type<mutex> { @@ -248,9 +254,10 @@ namespace boost private: Mutex& m; - explicit lock_guard(lock_guard&); - lock_guard& operator=(lock_guard&); public: + typedef Mutex mutex_type; + BOOST_THREAD_NO_COPYABLE(lock_guard) + explicit lock_guard(Mutex& m_): m(m_) { @@ -265,25 +272,29 @@ namespace boost } }; - template<typename Mutex> class unique_lock { private: Mutex* m; bool is_locked; - unique_lock(unique_lock&); + + private: explicit unique_lock(upgrade_lock<Mutex>&); - unique_lock& operator=(unique_lock&); unique_lock& operator=(upgrade_lock<Mutex>& other); public: -#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) - unique_lock(const volatile unique_lock&); + typedef Mutex mutex_type; + BOOST_THREAD_MOVABLE_ONLY(unique_lock) + +#if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF. +#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) + unique_lock(const volatile unique_lock&); #endif - unique_lock(): +#endif + unique_lock() BOOST_NOEXCEPT : m(0),is_locked(false) {} - + explicit unique_lock(Mutex& m_): m(&m_),is_locked(false) { @@ -292,7 +303,7 @@ namespace boost unique_lock(Mutex& m_,adopt_lock_t): m(&m_),is_locked(true) {} - unique_lock(Mutex& m_,defer_lock_t): + unique_lock(Mutex& m_,defer_lock_t) BOOST_NOEXCEPT: m(&m_),is_locked(false) {} unique_lock(Mutex& m_,try_to_lock_t): @@ -311,91 +322,172 @@ namespace boost { timed_lock(target_time); } -#ifndef BOOST_NO_RVALUE_REFERENCES - unique_lock(unique_lock&& other): - m(other.m),is_locked(other.is_locked) + +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + unique_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t) + : m(&mtx), is_locked(mtx.try_lock_until(t)) { - other.is_locked=false; - other.m=0; } - explicit unique_lock(upgrade_lock<Mutex>&& other); - - unique_lock<Mutex>&& move() + template <class Rep, class Period> + unique_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d) + : m(&mtx), is_locked(mtx.try_lock_for(d)) { - return static_cast<unique_lock<Mutex>&&>(*this); } +#endif + unique_lock(BOOST_THREAD_RV_REF(unique_lock) other) BOOST_NOEXCEPT: + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) + { + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; + } + BOOST_THREAD_EXPLICIT_LOCK_CONVERSION unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other); - unique_lock& operator=(unique_lock&& other) +#ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION + unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT { - unique_lock temp(other.move()); + unique_lock temp(::boost::move(other)); swap(temp); return *this; } +#endif - unique_lock& operator=(upgrade_lock<Mutex>&& other) + unique_lock& operator=(BOOST_THREAD_RV_REF(unique_lock) other) BOOST_NOEXCEPT { - unique_lock temp(other.move()); + unique_lock temp(::boost::move(other)); swap(temp); return *this; } - void swap(unique_lock&& other) - { - std::swap(m,other.m); - std::swap(is_locked,other.is_locked); - } -#else - unique_lock(detail::thread_move_t<unique_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) +#if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF. +#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) + unique_lock& operator=(unique_lock<Mutex> other) { - other->is_locked=false; - other->m=0; + swap(other); + return *this; } - unique_lock(detail::thread_move_t<upgrade_lock<Mutex> > other); +#endif // BOOST_WORKAROUND +#endif - operator detail::thread_move_t<unique_lock<Mutex> >() + // Conversion from upgrade locking + unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul, try_to_lock_t) + : m(0),is_locked(false) { - return move(); + if (BOOST_THREAD_RV(ul).owns_lock()) { + if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock()) + { + m = BOOST_THREAD_RV(ul).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(ul).release(); + } } - detail::thread_move_t<unique_lock<Mutex> > move() +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul, + const chrono::time_point<Clock, Duration>& abs_time) + : m(0),is_locked(false) { - return detail::thread_move_t<unique_lock<Mutex> >(*this); + if (BOOST_THREAD_RV(ul).owns_lock()) { + if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock_until(abs_time)) + { + m = BOOST_THREAD_RV(ul).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(ul).release(); + } } -#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) - unique_lock& operator=(unique_lock<Mutex> other) - { - swap(other); - return *this; - } -#else - unique_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other) + template <class Rep, class Period> + unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul, + const chrono::duration<Rep, Period>& rel_time) + : m(0),is_locked(false) { - unique_lock temp(other); - swap(temp); - return *this; + if (BOOST_THREAD_RV(ul).owns_lock()) { + if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock_for(rel_time)) + { + m = BOOST_THREAD_RV(ul).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(ul).release(); + } } #endif - unique_lock& operator=(detail::thread_move_t<upgrade_lock<Mutex> > other) +#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS + // Conversion from shared locking + unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, try_to_lock_t) + : m(0),is_locked(false) { - unique_lock temp(other); - swap(temp); - return *this; + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock()) + { + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } + } + +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, + const chrono::time_point<Clock, Duration>& abs_time) + : m(0),is_locked(false) + { + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_until(abs_time)) + { + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } } - void swap(detail::thread_move_t<unique_lock<Mutex> > other) + + template <class Rep, class Period> + unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, + const chrono::duration<Rep, Period>& rel_time) + : m(0),is_locked(false) { - std::swap(m,other->m); - std::swap(is_locked,other->is_locked); + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_for(rel_time)) + { + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } } -#endif - void swap(unique_lock& other) +#endif // BOOST_THREAD_USES_CHRONO +#endif // BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS + + + void swap(unique_lock& other) BOOST_NOEXCEPT { std::swap(m,other.m); std::swap(is_locked,other.is_locked); } - + ~unique_lock() { if(owns_lock()) @@ -405,18 +497,26 @@ namespace boost } void lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); } m->lock(); is_locked=true; } bool try_lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); } is_locked=m->try_lock(); return is_locked; @@ -424,50 +524,118 @@ namespace boost template<typename TimeDuration> bool timed_lock(TimeDuration const& relative_time) { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); + } is_locked=m->timed_lock(relative_time); return is_locked; } - + bool timed_lock(::boost::system_time const& absolute_time) { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); + } is_locked=m->timed_lock(absolute_time); return is_locked; } bool timed_lock(::boost::xtime const& absolute_time) { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); + } is_locked=m->timed_lock(absolute_time); return is_locked; } + +#ifdef BOOST_THREAD_USES_CHRONO + + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); + } + is_locked=m->try_lock_for(rel_time); + return is_locked; + } + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex")); + } + is_locked=m->try_lock_until(abs_time); + return is_locked; + } +#endif + void unlock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex")); + } if(!owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock doesn't own the mutex")); } m->unlock(); is_locked=false; } - + +#if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) typedef void (unique_lock::*bool_type)(); - operator bool_type() const + operator bool_type() const BOOST_NOEXCEPT { return is_locked?&unique_lock::lock:0; } - bool operator!() const + bool operator!() const BOOST_NOEXCEPT { return !owns_lock(); } - bool owns_lock() const +#else + explicit operator bool() const BOOST_NOEXCEPT + { + return owns_lock(); + } +#endif + bool owns_lock() const BOOST_NOEXCEPT { return is_locked; } - Mutex* mutex() const + Mutex* mutex() const BOOST_NOEXCEPT { return m; } - Mutex* release() + Mutex* release() BOOST_NOEXCEPT { Mutex* const res=m; m=0; @@ -479,44 +647,13 @@ namespace boost friend class upgrade_lock<Mutex>; }; -#ifndef BOOST_NO_RVALUE_REFERENCES - template<typename Mutex> - void swap(unique_lock<Mutex>&& lhs,unique_lock<Mutex>&& rhs) - { - lhs.swap(rhs); - } - - template<typename Mutex> - inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>&& ul) - { - return static_cast<upgrade_lock<Mutex>&&>(ul); - } - - template<typename Mutex> - inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>& ul) - { - return static_cast<upgrade_lock<Mutex>&&>(ul); - } -#endif template<typename Mutex> - void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs) + void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs) BOOST_NOEXCEPT { lhs.swap(rhs); } -#ifndef BOOST_NO_RVALUE_REFERENCES - template<typename Mutex> - inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul) - { - return static_cast<unique_lock<Mutex>&&>(ul); - } - - template<typename Mutex> - inline unique_lock<Mutex>&& move(unique_lock<Mutex>& ul) - { - return static_cast<unique_lock<Mutex>&&>(ul); - } -#endif + BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) unique_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END template<typename Mutex> class shared_lock @@ -524,14 +661,15 @@ namespace boost protected: Mutex* m; bool is_locked; - private: - explicit shared_lock(shared_lock&); - shared_lock& operator=(shared_lock&); + public: - shared_lock(): + typedef Mutex mutex_type; + BOOST_THREAD_MOVABLE_ONLY(shared_lock) + + shared_lock() BOOST_NOEXCEPT: m(0),is_locked(false) {} - + explicit shared_lock(Mutex& m_): m(&m_),is_locked(false) { @@ -540,7 +678,7 @@ namespace boost shared_lock(Mutex& m_,adopt_lock_t): m(&m_),is_locked(true) {} - shared_lock(Mutex& m_,defer_lock_t): + shared_lock(Mutex& m_,defer_lock_t) BOOST_NOEXCEPT: m(&m_),is_locked(false) {} shared_lock(Mutex& m_,try_to_lock_t): @@ -554,91 +692,90 @@ namespace boost timed_lock(target_time); } - shared_lock(detail::thread_move_t<shared_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + shared_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t) + : m(&mtx), is_locked(mtx.try_lock_shared_until(t)) + { + } + template <class Rep, class Period> + shared_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d) + : m(&mtx), is_locked(mtx.try_lock_shared_for(d)) + { + } +#endif + + shared_lock(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT: + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { - other->is_locked=false; - other->m=0; + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; } - shared_lock(detail::thread_move_t<unique_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) + BOOST_THREAD_EXPLICIT_LOCK_CONVERSION shared_lock(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other): + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { if(is_locked) { m->unlock_and_lock_shared(); } - other->is_locked=false; - other->m=0; + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; } - shared_lock(detail::thread_move_t<upgrade_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) + BOOST_THREAD_EXPLICIT_LOCK_CONVERSION shared_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other): + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { if(is_locked) { m->unlock_upgrade_and_lock_shared(); } - other->is_locked=false; - other->m=0; + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; } - operator detail::thread_move_t<shared_lock<Mutex> >() - { - return move(); - } - detail::thread_move_t<shared_lock<Mutex> > move() + shared_lock& operator=(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT { - return detail::thread_move_t<shared_lock<Mutex> >(*this); - } - - - shared_lock& operator=(detail::thread_move_t<shared_lock<Mutex> > other) - { - shared_lock temp(other); + shared_lock temp(::boost::move(other)); swap(temp); return *this; } - - shared_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other) +#ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION + shared_lock& operator=(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) { - shared_lock temp(other); + shared_lock temp(::boost::move(other)); swap(temp); return *this; } - shared_lock& operator=(detail::thread_move_t<upgrade_lock<Mutex> > other) + shared_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) { - shared_lock temp(other); + shared_lock temp(::boost::move(other)); swap(temp); return *this; } +#endif -#ifndef BOOST_NO_RVALUE_REFERENCES - void swap(shared_lock&& other) + void swap(shared_lock& other) BOOST_NOEXCEPT { std::swap(m,other.m); std::swap(is_locked,other.is_locked); } -#else - void swap(boost::detail::thread_move_t<shared_lock<Mutex> > other) - { - std::swap(m,other->m); - std::swap(is_locked,other->is_locked); - } -#endif - void swap(shared_lock& other) + + Mutex* mutex() const BOOST_NOEXCEPT { - std::swap(m,other.m); - std::swap(is_locked,other.is_locked); + return m; } - Mutex* mutex() const + Mutex* release() BOOST_NOEXCEPT { - return m; + Mutex* const res=m; + m=0; + is_locked=false; + return res; } - + ~shared_lock() { if(owns_lock()) @@ -648,27 +785,39 @@ namespace boost } void lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); } m->lock_shared(); is_locked=true; } bool try_lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); } is_locked=m->try_lock_shared(); return is_locked; } bool timed_lock(boost::system_time const& target_time) { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); } is_locked=m->timed_lock_shared(target_time); return is_locked; @@ -676,52 +825,91 @@ namespace boost template<typename Duration> bool timed_lock(Duration const& target_time) { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); } is_locked=m->timed_lock_shared(target_time); return is_locked; } +#ifdef BOOST_THREAD_USES_CHRONO + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); + } + is_locked=m->try_lock_shared_for(rel_time); + return is_locked; + } + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); + } + is_locked=m->try_lock_shared_until(abs_time); + return is_locked; + } +#endif void unlock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(!owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock doesn't own the mutex")); } m->unlock_shared(); is_locked=false; } - + +#if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) typedef void (shared_lock<Mutex>::*bool_type)(); - operator bool_type() const + operator bool_type() const BOOST_NOEXCEPT { return is_locked?&shared_lock::lock:0; } - bool operator!() const + bool operator!() const BOOST_NOEXCEPT { return !owns_lock(); } - bool owns_lock() const +#else + explicit operator bool() const BOOST_NOEXCEPT + { + return owns_lock(); + } +#endif + bool owns_lock() const BOOST_NOEXCEPT { return is_locked; } }; -#ifndef BOOST_NO_RVALUE_REFERENCES - template<typename Mutex> - void swap(shared_lock<Mutex>&& lhs,shared_lock<Mutex>&& rhs) - { - lhs.swap(rhs); - } -#else + BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) shared_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END + template<typename Mutex> - void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs) + void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs) BOOST_NOEXCEPT { lhs.swap(rhs); } -#endif template<typename Mutex> class upgrade_lock @@ -729,14 +917,15 @@ namespace boost protected: Mutex* m; bool is_locked; - private: - explicit upgrade_lock(upgrade_lock&); - upgrade_lock& operator=(upgrade_lock&); + public: - upgrade_lock(): + typedef Mutex mutex_type; + BOOST_THREAD_MOVABLE_ONLY(upgrade_lock) + + upgrade_lock() BOOST_NOEXCEPT: m(0),is_locked(false) {} - + explicit upgrade_lock(Mutex& m_): m(&m_),is_locked(false) { @@ -745,7 +934,7 @@ namespace boost upgrade_lock(Mutex& m_,adopt_lock_t): m(&m_),is_locked(true) {} - upgrade_lock(Mutex& m_,defer_lock_t): + upgrade_lock(Mutex& m_,defer_lock_t) BOOST_NOEXCEPT: m(&m_),is_locked(false) {} upgrade_lock(Mutex& m_,try_to_lock_t): @@ -753,89 +942,128 @@ namespace boost { try_lock(); } -#ifdef BOOST_HAS_RVALUE_REFS - upgrade_lock(upgrade_lock<Mutex>&& other): - m(other.m),is_locked(other.is_locked) + +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + upgrade_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t) + : m(&mtx), is_locked(mtx.try_lock_upgrade_until(t)) + { + } + template <class Rep, class Period> + upgrade_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d) + : m(&mtx), is_locked(mtx.try_lock_upgrade_for(d)) + { + } +#endif + + upgrade_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT: + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { - other.is_locked=false; - other.m=0; + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; } - upgrade_lock(unique_lock<Mutex>&& other): - m(other.m),is_locked(other.is_locked) + BOOST_THREAD_EXPLICIT_LOCK_CONVERSION upgrade_lock(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other): + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { if(is_locked) { m->unlock_and_lock_upgrade(); } - other.is_locked=false; - other.m=0; + BOOST_THREAD_RV(other).is_locked=false; + BOOST_THREAD_RV(other).m=0; } - upgrade_lock& operator=(upgrade_lock<Mutex>&& other) + upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT { - upgrade_lock temp(static_cast<upgrade_lock<Mutex>&&>(other)); + upgrade_lock temp(::boost::move(other)); swap(temp); return *this; } - upgrade_lock& operator=(unique_lock<Mutex>&& other) +#ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION + upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) { - upgrade_lock temp(static_cast<unique_lock<Mutex>&&>(other)); + upgrade_lock temp(::boost::move(other)); swap(temp); return *this; } -#else - upgrade_lock(detail::thread_move_t<upgrade_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) - { - other->is_locked=false; - other->m=0; - } +#endif - upgrade_lock(detail::thread_move_t<unique_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) +#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS + // Conversion from shared locking + upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, try_to_lock_t) + : m(0),is_locked(false) { - if(is_locked) + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade()) { - m->unlock_and_lock_upgrade(); + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; } - other->is_locked=false; - other->m=0; + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } } - operator detail::thread_move_t<upgrade_lock<Mutex> >() +#ifdef BOOST_THREAD_USES_CHRONO + template <class Clock, class Duration> + upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, + const chrono::time_point<Clock, Duration>& abs_time) + : m(0),is_locked(false) { - return move(); + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade_until(abs_time)) + { + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } } - detail::thread_move_t<upgrade_lock<Mutex> > move() + template <class Rep, class Period> + upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, + const chrono::duration<Rep, Period>& rel_time) + : m(0),is_locked(false) { - return detail::thread_move_t<upgrade_lock<Mutex> >(*this); + if (BOOST_THREAD_RV(sl).owns_lock()) { + if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade_for(rel_time)) + { + m = BOOST_THREAD_RV(sl).release(); + is_locked = true; + } + } + else + { + m = BOOST_THREAD_RV(sl).release(); + } } +#endif // BOOST_THREAD_USES_CHRONO +#endif // BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS - - upgrade_lock& operator=(detail::thread_move_t<upgrade_lock<Mutex> > other) + void swap(upgrade_lock& other) BOOST_NOEXCEPT { - upgrade_lock temp(other); - swap(temp); - return *this; + std::swap(m,other.m); + std::swap(is_locked,other.is_locked); } - - upgrade_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other) + Mutex* mutex() const BOOST_NOEXCEPT { - upgrade_lock temp(other); - swap(temp); - return *this; + return m; } -#endif - void swap(upgrade_lock& other) + Mutex* release() BOOST_NOEXCEPT { - std::swap(m,other.m); - std::swap(is_locked,other.is_locked); + Mutex* const res=m; + m=0; + is_locked=false; + return res; } - ~upgrade_lock() { if(owns_lock()) @@ -845,42 +1073,90 @@ namespace boost } void lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost upgrade_lock owns already the mutex")); } m->lock_upgrade(); is_locked=true; } bool try_lock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost upgrade_lock owns already the mutex")); } is_locked=m->try_lock_upgrade(); return is_locked; } void unlock() { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } if(!owns_lock()) { - boost::throw_exception(boost::lock_error()); + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost upgrade_lock doesn't own the mutex")); } m->unlock_upgrade(); is_locked=false; } - +#ifdef BOOST_THREAD_USES_CHRONO + template <class Rep, class Period> + bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); + } + is_locked=m->try_lock_upgrade_for(rel_time); + return is_locked; + } + template <class Clock, class Duration> + bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) + { + if(m==0) + { + boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost shared_lock has no mutex")); + } + if(owns_lock()) + { + boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost shared_lock owns already the mutex")); + } + is_locked=m->try_lock_upgrade_until(abs_time); + return is_locked; + } +#endif +#if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) typedef void (upgrade_lock::*bool_type)(); - operator bool_type() const + operator bool_type() const BOOST_NOEXCEPT { return is_locked?&upgrade_lock::lock:0; } - bool operator!() const + bool operator!() const BOOST_NOEXCEPT { return !owns_lock(); } - bool owns_lock() const +#else + explicit operator bool() const BOOST_NOEXCEPT + { + return owns_lock(); + } +#endif + bool owns_lock() const BOOST_NOEXCEPT { return is_locked; } @@ -888,30 +1164,25 @@ namespace boost friend class unique_lock<Mutex>; }; - -#ifndef BOOST_NO_RVALUE_REFERENCES template<typename Mutex> - unique_lock<Mutex>::unique_lock(upgrade_lock<Mutex>&& other): - m(other.m),is_locked(other.is_locked) + void swap(upgrade_lock<Mutex>& lhs,upgrade_lock<Mutex>& rhs) BOOST_NOEXCEPT { - other.is_locked=false; - if(is_locked) - { - m->unlock_upgrade_and_lock(); - } + lhs.swap(rhs); } -#else + + BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) upgrade_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END + template<typename Mutex> - unique_lock<Mutex>::unique_lock(detail::thread_move_t<upgrade_lock<Mutex> > other): - m(other->m),is_locked(other->is_locked) + unique_lock<Mutex>::unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other): + m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked) { - other->is_locked=false; if(is_locked) { m->unlock_upgrade_and_lock(); } + BOOST_THREAD_RV(other).release(); } -#endif + template <class Mutex> class upgrade_to_unique_lock { @@ -919,67 +1190,65 @@ namespace boost upgrade_lock<Mutex>* source; unique_lock<Mutex> exclusive; - explicit upgrade_to_unique_lock(upgrade_to_unique_lock&); - upgrade_to_unique_lock& operator=(upgrade_to_unique_lock&); public: + typedef Mutex mutex_type; + BOOST_THREAD_MOVABLE_ONLY(upgrade_to_unique_lock) + explicit upgrade_to_unique_lock(upgrade_lock<Mutex>& m_): - source(&m_),exclusive(move(*source)) + source(&m_),exclusive(::boost::move(*source)) {} ~upgrade_to_unique_lock() { if(source) { - *source=move(exclusive); + *source=BOOST_THREAD_MAKE_RV_REF(upgrade_lock<Mutex>(::boost::move(exclusive))); } } -#ifdef BOOST_HAS_RVALUE_REFS - upgrade_to_unique_lock(upgrade_to_unique_lock<Mutex>&& other): - source(other.source),exclusive(move(other.exclusive)) - { - other.source=0; - } - - upgrade_to_unique_lock& operator=(upgrade_to_unique_lock<Mutex>&& other) - { - upgrade_to_unique_lock temp(other); - swap(temp); - return *this; - } -#else - upgrade_to_unique_lock(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other): - source(other->source),exclusive(move(other->exclusive)) + upgrade_to_unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT: + source(BOOST_THREAD_RV(other).source),exclusive(::boost::move(BOOST_THREAD_RV(other).exclusive)) { - other->source=0; + BOOST_THREAD_RV(other).source=0; } - - upgrade_to_unique_lock& operator=(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other) + + upgrade_to_unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT { upgrade_to_unique_lock temp(other); swap(temp); return *this; } -#endif - void swap(upgrade_to_unique_lock& other) + + void swap(upgrade_to_unique_lock& other) BOOST_NOEXCEPT { std::swap(source,other.source); exclusive.swap(other.exclusive); } + +#if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) typedef void (upgrade_to_unique_lock::*bool_type)(upgrade_to_unique_lock&); - operator bool_type() const + operator bool_type() const BOOST_NOEXCEPT { return exclusive.owns_lock()?&upgrade_to_unique_lock::swap:0; } - bool operator!() const + bool operator!() const BOOST_NOEXCEPT { return !owns_lock(); } - bool owns_lock() const +#else + explicit operator bool() const BOOST_NOEXCEPT + { + return owns_lock(); + } +#endif + + bool owns_lock() const BOOST_NOEXCEPT { return exclusive.owns_lock(); } }; + BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) upgrade_to_unique_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END + namespace detail { template<typename Mutex> @@ -988,9 +1257,11 @@ namespace boost { typedef unique_lock<Mutex> base; public: + BOOST_THREAD_MOVABLE_ONLY(try_lock_wrapper) + try_lock_wrapper() {} - + explicit try_lock_wrapper(Mutex& m): base(m,try_to_lock) {} @@ -1004,54 +1275,27 @@ namespace boost try_lock_wrapper(Mutex& m_,try_to_lock_t): base(m_,try_to_lock) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - try_lock_wrapper(try_lock_wrapper&& other): - base(other.move()) +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other): + base(::boost::move(other)) {} - try_lock_wrapper&& move() - { - return static_cast<try_lock_wrapper&&>(*this); - } - - try_lock_wrapper& operator=(try_lock_wrapper<Mutex>&& other) - { - try_lock_wrapper temp(other.move()); - swap(temp); - return *this; - } +#elif defined BOOST_THREAD_USES_MOVE + try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other): + base(::boost::move(static_cast<base&>(other))) + {} - void swap(try_lock_wrapper&& other) - { - base::swap(other); - } #else - try_lock_wrapper(detail::thread_move_t<try_lock_wrapper<Mutex> > other): - base(detail::thread_move_t<base>(*other)) + try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other): + base(BOOST_THREAD_RV_REF(base)(*other)) {} - - operator detail::thread_move_t<try_lock_wrapper<Mutex> >() - { - return move(); - } - - detail::thread_move_t<try_lock_wrapper<Mutex> > move() - { - return detail::thread_move_t<try_lock_wrapper<Mutex> >(*this); - } - - try_lock_wrapper& operator=(detail::thread_move_t<try_lock_wrapper<Mutex> > other) +#endif + try_lock_wrapper& operator=(BOOST_THREAD_RV_REF_BEG try_lock_wrapper<Mutex> BOOST_THREAD_RV_REF_END other) { try_lock_wrapper temp(other); swap(temp); return *this; } - - void swap(detail::thread_move_t<try_lock_wrapper<Mutex> > other) - { - base::swap(*other); - } -#endif void swap(try_lock_wrapper& other) { base::swap(other); @@ -1080,32 +1324,31 @@ namespace boost { return base::release(); } - bool operator!() const - { - return !this->owns_lock(); - } +#if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) typedef typename base::bool_type bool_type; operator bool_type() const { return base::operator bool_type(); } + bool operator!() const + { + return !this->owns_lock(); + } +#else + explicit operator bool() const + { + return owns_lock(); + } +#endif }; -#ifndef BOOST_NO_RVALUE_REFERENCES - template<typename Mutex> - void swap(try_lock_wrapper<Mutex>&& lhs,try_lock_wrapper<Mutex>&& rhs) - { - lhs.swap(rhs); - } -#else template<typename Mutex> void swap(try_lock_wrapper<Mutex>& lhs,try_lock_wrapper<Mutex>& rhs) { lhs.swap(rhs); } -#endif - + template<typename MutexType1,typename MutexType2> unsigned try_lock_internal(MutexType1& m1,MutexType2& m2) { @@ -1234,7 +1477,7 @@ namespace boost template<bool x> struct is_mutex_type_wrapper {}; - + template<typename MutexType1,typename MutexType2> void lock_impl(MutexType1& m1,MutexType2& m2,is_mutex_type_wrapper<true>) { @@ -1262,7 +1505,7 @@ namespace boost template<typename Iterator> void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>); } - + template<typename MutexType1,typename MutexType2> void lock(MutexType1& m1,MutexType2& m2) @@ -1407,7 +1650,7 @@ namespace boost { typedef int type; }; - + template<typename Iterator> struct try_lock_impl_return<Iterator,false> { @@ -1423,7 +1666,7 @@ namespace boost template<typename Iterator> Iterator try_lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>); } - + template<typename MutexType1,typename MutexType2> typename detail::try_lock_impl_return<MutexType1>::type try_lock(MutexType1& m1,MutexType2& m2) { @@ -1465,7 +1708,7 @@ namespace boost { return ((int)detail::try_lock_internal(m1,m2,m3,m4,m5))-1; } - + namespace detail { @@ -1474,13 +1717,13 @@ namespace boost { Iterator begin; Iterator end; - + range_lock_guard(Iterator begin_,Iterator end_): begin(begin_),end(end_) { - lock(begin,end); + boost::lock(begin,end); } - + void release() { begin=end; @@ -1505,21 +1748,21 @@ namespace boost } typedef typename std::iterator_traits<Iterator>::value_type lock_type; unique_lock<lock_type> guard(*begin,try_to_lock); - + if(!guard.owns_lock()) { return begin; } - Iterator const failed=try_lock(++begin,end); + Iterator const failed=boost::try_lock(++begin,end); if(failed==end) { guard.release(); } - + return failed; } } - + namespace detail { @@ -1527,7 +1770,7 @@ namespace boost void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>) { typedef typename std::iterator_traits<Iterator>::value_type lock_type; - + if(begin==end) { return; @@ -1536,14 +1779,14 @@ namespace boost Iterator second=begin; ++second; Iterator next=second; - + for(;;) { unique_lock<lock_type> begin_lock(*begin,defer_lock); if(start_with_begin) { begin_lock.lock(); - Iterator const failed_lock=try_lock(next,end); + Iterator const failed_lock=boost::try_lock(next,end); if(failed_lock==end) { begin_lock.release(); @@ -1557,7 +1800,7 @@ namespace boost detail::range_lock_guard<Iterator> guard(next,end); if(begin_lock.try_lock()) { - Iterator const failed_lock=try_lock(second,next); + Iterator const failed_lock=boost::try_lock(second,next); if(failed_lock==next) { begin_lock.release(); @@ -1575,11 +1818,10 @@ namespace boost } } } - + } - -} +} #include <boost/config/abi_suffix.hpp> #endif |