|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85811 - in trunk: boost/sync/detail boost/sync/detail/event boost/sync/detail/mutexes boost/sync/mutexes boost/sync/support libs/sync/test/run
From: andrey.semashev_at_[hidden]
Date: 2013-09-21 15:03:30
Author: andysem
Date: 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013)
New Revision: 85811
URL: http://svn.boost.org/trac/boost/changeset/85811
Log:
Ported timed mutex for Windows. Changed time units to allow for non-system clocks. Minor fixes.
Added:
trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp (contents, props changed)
Text files modified:
trunk/boost/sync/detail/event/event_futex.hpp | 18 +--
trunk/boost/sync/detail/mutexes/mutex_windows.hpp | 10 +
trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp | 37 +++++++
trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp | 175 ++++++++++++++++++++++++++++++++++++++
trunk/boost/sync/detail/time_units.hpp | 182 ++++++++++++++++++++++-----------------
trunk/boost/sync/mutexes/timed_mutex.hpp | 36 +++++++
trunk/boost/sync/support/date_time.hpp | 22 ++--
trunk/libs/sync/test/run/mutex_test.cpp | 2
8 files changed, 373 insertions(+), 109 deletions(-)
Modified: trunk/boost/sync/detail/event/event_futex.hpp
==============================================================================
--- trunk/boost/sync/detail/event/event_futex.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/detail/event/event_futex.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -9,20 +9,18 @@
#ifndef BOOST_SYNC_DETAIL_EVENT_EVENT_FUTEX_HPP_INCLUDED
#define BOOST_SYNC_DETAIL_EVENT_EVENT_FUTEX_HPP_INCLUDED
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/shared_mutex.hpp>
-#include <boost/thread/locks.hpp>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/syscall.h>
+#include <linux/futex.h>
+#include <limits>
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
#include <boost/sync/detail/config.hpp>
#include <boost/sync/detail/header.hpp>
-#include <boost/atomic.hpp>
-
-#include <sys/time.h>
-#include <linux/futex.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-
namespace boost {
namespace sync {
BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {
Modified: trunk/boost/sync/detail/mutexes/mutex_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/mutex_windows.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/detail/mutexes/mutex_windows.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -39,8 +39,12 @@
BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {
+class timed_mutex;
+
class mutex
{
+ friend class timed_mutex;
+
private:
enum
{
@@ -102,7 +106,7 @@
}
}
- bool try_lock() BOOST_NOEXCEPT
+ bool try_lock()
{
return !sync::detail::windows::interlocked_bit_test_and_set(&m_active_count, lock_flag_bit);
}
@@ -170,7 +174,7 @@
}
};
-} // namespace posix
+} // namespace winnt
} // namespace sync
@@ -178,4 +182,4 @@
#include <boost/sync/detail/footer.hpp>
-#endif // BOOST_SYNC_DETAIL_MUTEXES_MUTEX_POSIX_HPP_INCLUDED_
+#endif // BOOST_SYNC_DETAIL_MUTEXES_MUTEX_WINDOWS_HPP_INCLUDED_
Modified: trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -199,6 +199,18 @@
return priv_timed_lock(sync::detail::time_traits< Time >::to_sync_unit(t));
}
+ template< typename Duration >
+ typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
+ {
+ return priv_timed_lock(sync::detail::time_traits< Duration >::to_sync_unit(t));
+ }
+
+ template< typename TimePoint >
+ typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
+ {
+ return priv_timed_lock(sync::detail::time_traits< TimePoint >::to_sync_unit(t));
+ }
+
native_handle_type native_handle() BOOST_NOEXCEPT
{
return &m_mutex;
@@ -208,12 +220,12 @@
BOOST_DELETED_FUNCTION(timed_mutex& operator= (timed_mutex const&))
private:
- bool priv_timed_lock(sync::detail::duration dur)
+ bool priv_timed_lock(sync::detail::system_duration dur)
{
- return priv_timed_lock(sync::detail::time_point::now() + dur);
+ return priv_timed_lock(sync::detail::system_time_point::now() + dur);
}
- bool priv_timed_lock(sync::detail::time_point const& t)
+ bool priv_timed_lock(sync::detail::system_time_point const& t)
{
#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
@@ -241,6 +253,25 @@
#endif // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
}
+
+ template< typename TimePoint >
+ bool priv_timed_lock(sync::detail::chrono_time_point< TimePoint > const& t)
+ {
+ if (m_mutex.try_lock())
+ return true;
+
+ typedef TimePoint time_point;
+ typedef typename time_point::clock clock;
+ typedef typename time_point::duration duration;
+ time_point now = clock::now();
+ while (now < t.get())
+ {
+ if (priv_timed_lock(sync::detail::time_traits< duration >::to_sync_unit(t.get() - now)))
+ return true;
+ now = clock::now();
+ }
+ return false;
+ }
};
} // namespace posix
Added: trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -0,0 +1,175 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * (C) Copyright 2007-2008 Anthony Williams
+ * (C) Copyright 2012-2013 Vicente J. Botet Escriba
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file detail/mutexes/timed_mutex_windows.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_MUTEXES_TIMED_MUTEX_WINDOWS_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_MUTEXES_TIMED_MUTEX_WINDOWS_HPP_INCLUDED_
+
+#include <cstddef>
+#include <limits>
+#include <boost/cstdint.hpp>
+#include <boost/assert.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/detail/winapi/handles.hpp>
+#include <boost/detail/winapi/synchronization.hpp>
+#include <boost/sync/exceptions/lock_error.hpp>
+#include <boost/sync/exceptions/resource_error.hpp>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/interlocked.hpp>
+#include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/time_units.hpp>
+#include <boost/sync/detail/mutexes/mutex_windows.hpp>
+
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {
+
+class timed_mutex
+{
+private:
+ mutex m_mutex;
+
+public:
+ BOOST_CONSTEXPR timed_mutex() BOOST_NOEXCEPT : m_mutex()
+ {
+ }
+
+ void lock()
+ {
+ m_mutex.lock();
+ }
+
+ void unlock() BOOST_NOEXCEPT
+ {
+ m_mutex.unlock();
+ }
+
+ bool try_lock()
+ {
+ return m_mutex.try_lock();
+ }
+
+ template< typename Time >
+ typename enable_if_c< sync::detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& t)
+ {
+ return priv_timed_lock(sync::detail::time_traits< Time >::to_sync_unit(t));
+ }
+
+ template< typename Duration >
+ typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
+ {
+ return priv_timed_lock(sync::detail::time_traits< Duration >::to_sync_unit(t));
+ }
+
+ template< typename TimePoint >
+ typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
+ {
+ return priv_timed_lock(sync::detail::time_traits< TimePoint >::to_sync_unit(t));
+ }
+
+ BOOST_DELETED_FUNCTION(timed_mutex(timed_mutex const&))
+ BOOST_DELETED_FUNCTION(timed_mutex& operator= (timed_mutex const&))
+
+private:
+ bool priv_timed_lock(sync::detail::system_time_point const& t)
+ {
+ return priv_timed_lock(t - sync::detail::system_time_point::now());
+ }
+
+ bool priv_timed_lock(sync::detail::system_duration const& t)
+ {
+ if (m_mutex.try_lock())
+ return true;
+
+ long old_count = m_mutex.m_active_count;
+ m_mutex.mark_waiting_and_try_lock(old_count);
+
+ if ((old_count & mutex::lock_flag_value) != 0)
+ {
+ bool lock_acquired = false;
+ boost::detail::winapi::HANDLE_ const evt = m_mutex.get_event();
+
+ uint64_t time_left = t.get();
+ do
+ {
+ const unsigned int dur = time_left > (std::numeric_limits< int >::max)() ?
+ static_cast< unsigned int >((std::numeric_limits< int >::max)()) : static_cast< unsigned int >(time_left);
+ const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(evt, dur);
+ switch (res)
+ {
+ case boost::detail::winapi::wait_object_0:
+ m_mutex.clear_waiting_and_try_lock(old_count);
+ lock_acquired = (old_count & mutex::lock_flag_value) == 0;
+ break;
+
+ case boost::detail::winapi::wait_timeout:
+ time_left -= dur;
+ break;
+
+ default:
+ BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in WaitForSingleObject"));
+ }
+ }
+ while (!lock_acquired && time_left > 0);
+
+ if (!lock_acquired)
+ {
+ BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ template< typename TimePoint >
+ bool priv_timed_lock(sync::detail::chrono_time_point< TimePoint > const& t)
+ {
+ if (m_mutex.try_lock())
+ return true;
+
+ typedef TimePoint time_point;
+ typedef typename time_point::clock clock;
+ typedef typename time_point::duration duration;
+ time_point now = clock::now();
+ while (now < t.get())
+ {
+ if (priv_timed_lock(sync::detail::time_traits< duration >::to_sync_unit(t.get() - now)))
+ return true;
+ now = clock::now();
+ }
+ return false;
+ }
+};
+
+} // namespace winnt
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_MUTEXES_TIMED_MUTEX_WINDOWS_HPP_INCLUDED_
Modified: trunk/boost/sync/detail/time_units.hpp
==============================================================================
--- trunk/boost/sync/detail/time_units.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/detail/time_units.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -34,64 +34,70 @@
namespace detail {
-#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
-
-class duration
+class system_duration
{
public:
typedef int64_t native_type;
+
+#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
// The native duration is in nanoseconds
static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = 1000000000u;
+#elif defined(BOOST_SYNC_DETAIL_PLATFORM_WINAPI)
+ // The native duration is in milliseconds
+ static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = 1000u;
+#endif
private:
native_type m_value;
public:
- duration() : m_value(0) {}
- explicit duration(native_type value) : m_value(value) {}
+ system_duration() : m_value(0) {}
+ explicit system_duration(native_type value) : m_value(value) {}
native_type get() const { return m_value; }
- duration& operator+= (duration const& that)
+ system_duration& operator+= (system_duration const& that)
{
m_value += that.m_value;
return *this;
}
- duration& operator-= (duration const& that)
+ system_duration& operator-= (system_duration const& that)
{
m_value -= that.m_value;
return *this;
}
- duration operator- () const
+ system_duration operator- () const
{
- return duration(-m_value);
+ return system_duration(-m_value);
}
- friend duration operator+ (duration left, duration const& right)
+ friend system_duration operator+ (system_duration left, system_duration const& right)
{
left += right;
return left;
}
- friend duration operator- (duration left, duration const& right)
+ friend system_duration operator- (system_duration left, system_duration const& right)
{
left -= right;
return left;
}
};
-class time_point
+#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
+
+class system_time_point
{
public:
typedef struct ::timespec native_type;
// The native subsecond precision is nanoseconds
- static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = duration::subsecond_fraction;
+ static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = system_duration::subsecond_fraction;
private:
native_type m_value;
public:
- time_point() : m_value() {}
- explicit time_point(time_t t, unsigned int subsecond = 0)
+ system_time_point() : m_value() {}
+ explicit system_time_point(time_t t, unsigned int subsecond = 0)
{
m_value.tv_sec = t;
m_value.tv_nsec = subsecond;
@@ -99,119 +105,76 @@
native_type const& get() const { return m_value; }
- static time_point now()
+ static system_time_point now()
{
#if defined(BOOST_HAS_CLOCK_GETTIME)
- time_point t;
+ system_time_point t;
::clock_gettime(CLOCK_REALTIME, &t.m_value);
return t;
#else
- return time_point(::time(0));
+ return system_time_point(::time(0));
#endif
}
- time_point& operator+= (duration const& dur)
+ system_time_point& operator+= (system_duration const& dur)
{
int64_t nsec = static_cast< int64_t >(m_value.tv_nsec) + dur.get();
- int64_t tv_nsec = nsec % duration::subsecond_fraction;
+ int64_t tv_nsec = nsec % system_duration::subsecond_fraction;
if (tv_nsec < 0)
{
tv_nsec += subsecond_fraction;
--m_value.tv_sec;
}
m_value.tv_nsec = tv_nsec;
- m_value.tv_sec += nsec / duration::subsecond_fraction;
+ m_value.tv_sec += nsec / system_duration::subsecond_fraction;
return *this;
}
- time_point& operator-= (duration const& dur)
+ system_time_point& operator-= (system_duration const& dur)
{
return operator+= (-dur);
}
- friend time_point operator+ (time_point left, duration const& right)
+ friend system_time_point operator+ (system_time_point left, system_duration const& right)
{
left += right;
return left;
}
- friend time_point operator- (time_point left, duration const& right)
+ friend system_time_point operator- (system_time_point left, system_duration const& right)
{
left -= right;
return left;
}
- friend duration operator- (time_point const& left, time_point const& right)
+ friend system_duration operator- (system_time_point const& left, system_time_point const& right)
{
int64_t seconds = static_cast< int64_t >(left.m_value.tv_sec) - static_cast< int64_t >(right.m_value.tv_sec);
int64_t nseconds = static_cast< int64_t >(left.m_value.tv_nsec) - static_cast< int64_t >(right.m_value.tv_nsec);
- return duration(seconds * duration::subsecond_fraction + nseconds);
+ return system_duration(seconds * system_duration::subsecond_fraction + nseconds);
}
};
#elif defined(BOOST_SYNC_DETAIL_PLATFORM_WINAPI)
-class duration
-{
-public:
- typedef int64_t native_type;
- // The native duration is in milliseconds
- static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = 1000u;
-
-private:
- native_type m_value;
-
-public:
- duration() : m_value(0) {}
- explicit duration(native_type value) : m_value(value) {}
-
- native_type get() const { return m_value; }
-
- duration& operator+= (duration const& that)
- {
- m_value += that.m_value;
- return *this;
- }
- duration& operator-= (duration const& that)
- {
- m_value -= that.m_value;
- return *this;
- }
- duration operator- () const
- {
- return duration(-m_value);
- }
-
- friend duration operator+ (duration left, duration const& right)
- {
- left += right;
- return left;
- }
- friend duration operator- (duration left, duration const& right)
- {
- left -= right;
- return left;
- }
-};
-
-class time_point
+class system_time_point
{
public:
typedef uint64_t native_type;
// The native subsecond precision is milliseconds
- static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = duration::subsecond_fraction;
+ static BOOST_CONSTEXPR_OR_CONST uint64_t subsecond_fraction = system_duration::subsecond_fraction;
private:
native_type m_value;
public:
- time_point() : m_value(0) {}
- explicit time_point(time_t t, unsigned int subsecond = 0) : m_value(static_cast< uint64_t >(t) * subsecond_fraction + subsecond)
+ system_time_point() : m_value(0) {}
+ explicit system_time_point(time_t t, unsigned int subsecond = 0) : m_value(static_cast< uint64_t >(t) * subsecond_fraction + subsecond)
{
}
native_type const& get() const { return m_value; }
- static time_point now()
+ static system_time_point now()
{
union
{
@@ -228,41 +191,98 @@
// Convert to milliseconds
caster.as_uint64 /= 10000u;
- time_point res;
+ system_time_point res;
res.m_value = caster.as_uint64;
return res;
}
- time_point& operator+= (duration const& dur)
+ system_time_point& operator+= (system_duration const& dur)
{
m_value += dur.get();
return *this;
}
- time_point& operator-= (duration const& dur)
+ system_time_point& operator-= (system_duration const& dur)
{
m_value -= dur.get();
return *this;
}
- friend time_point operator+ (time_point left, duration const& right)
+ friend system_time_point operator+ (system_time_point left, system_duration const& right)
{
left += right;
return left;
}
- friend time_point operator- (time_point left, duration const& right)
+ friend system_time_point operator- (system_time_point left, system_duration const& right)
{
left -= right;
return left;
}
- friend duration operator- (time_point const& left, time_point const& right)
+ friend system_duration operator- (system_time_point const& left, system_time_point const& right)
{
- return duration(static_cast< duration::native_type >(left.m_value - right.m_value));
+ return system_duration(static_cast< system_duration::native_type >(left.m_value - right.m_value));
}
};
#endif
+template< typename TimePoint >
+class chrono_time_point :
+ public TimePoint
+{
+public:
+ typedef TimePoint time_point;
+ typedef typename time_point::clock clock;
+ typedef typename time_point::duration duration;
+
+private:
+ time_point m_value;
+
+public:
+ BOOST_DEFAULTED_FUNCTION(chrono_time_point(), : m_value() {})
+ BOOST_DEFAULTED_FUNCTION(chrono_time_point(chrono_time_point const& that), : m_value(that.m_value) {})
+
+ explicit chrono_time_point(time_point const& that) : m_value(that)
+ {
+ }
+
+ template< typename T >
+ explicit chrono_time_point(T const& arg) : base_type(arg)
+ {
+ }
+
+ time_point const& get() const { return m_value; }
+
+ static chrono_time_point now() { return chrono_time_point(clock::now()); }
+
+ chrono_time_point& operator+= (duration const& dur)
+ {
+ m_value += dur;
+ return *this;
+ }
+ chrono_time_point& operator-= (duration const& dur)
+ {
+ m_value -= dur;
+ return *this;
+ }
+
+ friend chrono_time_point operator+ (chrono_time_point left, duration const& right)
+ {
+ left.m_value += right;
+ return left;
+ }
+ friend chrono_time_point operator- (chrono_time_point left, duration const& right)
+ {
+ left.m_value -= right;
+ return left;
+ }
+
+ friend duration operator- (chrono_time_point const& left, chrono_time_point const& right)
+ {
+ return left.m_value - right.m_value;
+ }
+};
+
} // namespace detail
} // namespace sync
Modified: trunk/boost/sync/mutexes/timed_mutex.hpp
==============================================================================
--- trunk/boost/sync/mutexes/timed_mutex.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/mutexes/timed_mutex.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -76,6 +76,8 @@
* which can be an absolute time point or a duration. If the operation completes successfully until the timeout expires, \c true is returned.
* Otherwise, returns \c false.
*
+ * \param time Relative or absolute timeout. If timeout is relative, the time is measured according to the system clock.
+ *
* \b Throws: An exception in case if the operating system is unable to fulfill the request.
*
* \note In order to use this method, a supplementary header must be included from boost/sync/support to enable support for particular time units.
@@ -84,6 +86,38 @@
bool timed_lock(Time time);
/*!
+ * \brief Attempts to lock the mutex within the specified timeout
+ *
+ * If the mutex is not locked, the method locks it and returns \c true. Otherwise the method blocks for up to \a time timeout,
+ * which is a duration. If the operation completes successfully until the timeout expires, \c true is returned.
+ * Otherwise, returns \c false.
+ *
+ * \param rel_timeout Relative timeout. The time is measured according to the system clock.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ *
+ * \note In order to use this method, a supplementary header must be included from boost/sync/support to enable support for particular time units.
+ */
+ template< typename Duration >
+ bool try_lock_for(Duration rel_timeout);
+
+ /*!
+ * \brief Attempts to lock the mutex within the specified timeout
+ *
+ * If the mutex is not locked, the method locks it and returns \c true. Otherwise the method blocks for up to \a time timeout,
+ * which is an absolute time point. If the operation completes successfully until the timeout expires, \c true is returned.
+ * Otherwise, returns \c false.
+ *
+ * \param abs_timeout Absolute timeout. If the time point clock is not compatible with system clock the operation may take considerably longer than the specified timeout.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ *
+ * \note In order to use this method, a supplementary header must be included from boost/sync/support to enable support for particular time units.
+ */
+ template< typename TimePoint >
+ bool try_lock_until(TimePoint abs_timeout);
+
+ /*!
* \brief Unlocks the mutex
*
* Releases the mutex that has been locked by the current thread.
@@ -115,7 +149,7 @@
#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
#include <boost/sync/detail/mutexes/timed_mutex_posix.hpp>
#elif defined(BOOST_SYNC_DETAIL_PLATFORM_WINAPI)
-//#include <boost/sync/detail/mutexes/timed_mutex_windows.hpp>
+#include <boost/sync/detail/mutexes/timed_mutex_windows.hpp>
#else
#error Boost.Sync: Unsupported threading API
#endif
Modified: trunk/boost/sync/support/date_time.hpp
==============================================================================
--- trunk/boost/sync/support/date_time.hpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/boost/sync/support/date_time.hpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -38,16 +38,17 @@
static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
- static duration to_sync_unit(T const& dur)
+ static system_duration to_sync_unit(T const& dur)
{
typedef typename T::traits_type traits_type;
enum
{
- conversion_ratio = traits_type::ticks_per_second >= duration::subsecond_fraction ?
- traits_type::ticks_per_second / duration::subsecond_fraction :
- duration::subsecond_fraction / traits_type::ticks_per_second
+ conversion_ratio = traits_type::ticks_per_second >= system_duration::subsecond_fraction ?
+ traits_type::ticks_per_second / system_duration::subsecond_fraction :
+ system_duration::subsecond_fraction / traits_type::ticks_per_second
};
- return duration(traits_type::ticks_per_second >= duration::subsecond_fraction ? dur.ticks() / conversion_ratio : dur.ticks() * conversion_ratio);
+ return system_duration(traits_type::ticks_per_second >= system_duration::subsecond_fraction ?
+ dur.ticks() / conversion_ratio : dur.ticks() * conversion_ratio);
}
};
@@ -58,7 +59,7 @@
static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
- static time_point to_sync_unit(T const& point)
+ static system_time_point to_sync_unit(T const& point)
{
typedef typename T::date_type date_type;
typedef typename T::time_duration_type time_duration_type;
@@ -70,11 +71,12 @@
typedef typename time_duration_type::traits_type traits_type;
enum
{
- conversion_ratio = traits_type::ticks_per_second >= time_point::subsecond_fraction ?
- traits_type::ticks_per_second / time_point::subsecond_fraction :
- time_point::subsecond_fraction / traits_type::ticks_per_second
+ conversion_ratio = traits_type::ticks_per_second >= system_time_point::subsecond_fraction ?
+ traits_type::ticks_per_second / system_time_point::subsecond_fraction :
+ system_time_point::subsecond_fraction / traits_type::ticks_per_second
};
- return time_point(seconds, traits_type::ticks_per_second >= time_point::subsecond_fraction ? fractional_seconds / conversion_ratio : fractional_seconds * conversion_ratio);
+ return system_time_point(seconds, traits_type::ticks_per_second >= time_point::subsecond_fraction ?
+ fractional_seconds / conversion_ratio : fractional_seconds * conversion_ratio);
}
};
Modified: trunk/libs/sync/test/run/mutex_test.cpp
==============================================================================
--- trunk/libs/sync/test/run/mutex_test.cpp Sat Sep 21 12:45:07 2013 (r85810)
+++ trunk/libs/sync/test/run/mutex_test.cpp 2013-09-21 15:03:30 EDT (Sat, 21 Sep 2013) (r85811)
@@ -179,7 +179,7 @@
struct test_timedlock
{
typedef M mutex_type;
- typedef typename M::scoped_timed_lock timed_lock_type;
+ typedef boost::sync::unique_lock< mutex_type > lock_type;
static bool fake_predicate()
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk