#include <boost/interprocess/exceptions.hpp>
#include <boost/move/utility_core.hpp>
-#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
//!\file
//!Describes the upgradable_lock class that serves to acquire the upgradable
//!Effects: Default constructs a upgradable_lock.
//!Postconditions: owns() == false and mutex() == 0.
- upgradable_lock()
+ upgradable_lock() BOOST_NOEXCEPT
: mp_mutex(0), m_locked(false)
{}
//! handles recursive locking depends upon the mutex. If the mutex_type
//! does not support timed_lock_upgradable, this constructor will fail
//! at compile time if instantiated, but otherwise have no effect.
- upgradable_lock(mutex_type& m, const boost::posix_time::ptime& abs_time)
+ template<class TimePoint>
+ upgradable_lock(mutex_type& m, const TimePoint& abs_time)
: mp_mutex(&m), m_locked(false)
{ m_locked = mp_mutex->timed_lock_upgradable(abs_time); }
//! signature. An non-moved upgradable_lock can be moved with the
//! expression: "boost::move(lock);". This constructor does not alter the
//! state of the mutex, only potentially who owns it.
- upgradable_lock(BOOST_RV_REF(upgradable_lock<mutex_type>) upgr)
+ upgradable_lock(BOOST_RV_REF(upgradable_lock<mutex_type>) upgr) BOOST_NOEXCEPT
: mp_mutex(0), m_locked(upgr.owns())
{ mp_mutex = upgr.release(); }
//!Notes: The destructor behavior ensures that the mutex lock is not leaked.
~upgradable_lock()
{
- try{
+ BOOST_TRY{
if(m_locked && mp_mutex) mp_mutex->unlock_upgradable();
}
- catch(...){}
+ BOOST_CATCH(...){} BOOST_CATCH_END
}
//!Effects: If owns(), then unlock_upgradable() is called on mutex().
//! specified time. If the mutex_type does not support
//! timed_lock_upgradable(abs_time), this function will fail at compile
//! time if instantiated, but otherwise have no effect.
- bool timed_lock(const boost::posix_time::ptime& abs_time)
+ template<class TimePoint>
+ bool timed_lock(const TimePoint& abs_time)
{
if(!mp_mutex || m_locked)
throw lock_exception();
//!Effects: Returns true if this scoped_lock has acquired the
//!referenced mutex.
- bool owns() const
+ bool owns() const BOOST_NOEXCEPT
{ return m_locked && mp_mutex; }
//!Conversion to bool.
//!Returns owns().
- operator unspecified_bool_type() const
+ operator unspecified_bool_type() const BOOST_NOEXCEPT
{ return m_locked? &this_type::m_locked : 0; }
//!Effects: Returns a pointer to the referenced mutex, or 0 if
//!there is no mutex to reference.
- mutex_type* mutex() const
+ mutex_type* mutex() const BOOST_NOEXCEPT
{ return mp_mutex; }
//!Effects: Returns a pointer to the referenced mutex, or 0 if there is no
//! mutex to reference.
//!Postconditions: mutex() == 0 and owns() == false.
- mutex_type* release()
+ mutex_type* release() BOOST_NOEXCEPT
{
mutex_type *mut = mp_mutex;
mp_mutex = 0;
//!Effects: Swaps state with moved lock.
//!Throws: Nothing.
- void swap(upgradable_lock<mutex_type> &other)
+ void swap(upgradable_lock<mutex_type> &other) BOOST_NOEXCEPT
{
(simple_swap)(mp_mutex, other.mp_mutex);
(simple_swap)(m_locked, other.m_locked);