summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp')
-rw-r--r--3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp85
1 files changed, 74 insertions, 11 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp b/3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp
index e56c8c3..6b81e5d 100644
--- a/3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp
+++ b/3rdParty/Boost/src/boost/asio/detail/chrono_time_traits.hpp
@@ -2,7 +2,7 @@
// detail/chrono_time_traits.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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)
@@ -15,7 +15,7 @@
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/cstdint.hpp>
+#include <boost/asio/detail/cstdint.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -23,6 +23,13 @@ namespace boost {
namespace asio {
namespace detail {
+// Helper template to compute the greatest common divisor.
+template <int64_t v1, int64_t v2>
+struct gcd { enum { value = gcd<v2, v1 % v2>::value }; };
+
+template <int64_t v1>
+struct gcd<v1, 0> { enum { value = v1 }; };
+
// Adapts std::chrono clocks for use with a deadline timer.
template <typename Clock, typename WaitTraits>
struct chrono_time_traits
@@ -48,13 +55,63 @@ struct chrono_time_traits
// Add a duration to a time.
static time_type add(const time_type& t, const duration_type& d)
{
+ const time_type epoch;
+ if (t >= epoch)
+ {
+ if ((time_type::max)() - t < d)
+ return (time_type::max)();
+ }
+ else // t < epoch
+ {
+ if (-(t - (time_type::min)()) > d)
+ return (time_type::min)();
+ }
+
return t + d;
}
// Subtract one time from another.
static duration_type subtract(const time_type& t1, const time_type& t2)
{
- return t1 - t2;
+ const time_type epoch;
+ if (t1 >= epoch)
+ {
+ if (t2 >= epoch)
+ {
+ return t1 - t2;
+ }
+ else if (t2 == (time_type::min)())
+ {
+ return (duration_type::max)();
+ }
+ else if ((time_type::max)() - t1 < epoch - t2)
+ {
+ return (duration_type::max)();
+ }
+ else
+ {
+ return t1 - t2;
+ }
+ }
+ else // t1 < epoch
+ {
+ if (t2 < epoch)
+ {
+ return t1 - t2;
+ }
+ else if (t1 == (time_type::min)())
+ {
+ return (duration_type::min)();
+ }
+ else if ((time_type::max)() - t2 < epoch - t1)
+ {
+ return (duration_type::min)();
+ }
+ else
+ {
+ return -(t2 - t1);
+ }
+ }
}
// Test whether one time is less than another.
@@ -73,32 +130,38 @@ struct chrono_time_traits
{
}
- boost::int64_t ticks() const
+ int64_t ticks() const
{
return d_.count();
}
- boost::int64_t total_seconds() const
+ int64_t total_seconds() const
{
return duration_cast<1, 1>();
}
- boost::int64_t total_milliseconds() const
+ int64_t total_milliseconds() const
{
return duration_cast<1, 1000>();
}
- boost::int64_t total_microseconds() const
+ int64_t total_microseconds() const
{
return duration_cast<1, 1000000>();
}
private:
- template <boost::int64_t Num, boost::int64_t Den>
- boost::int64_t duration_cast() const
+ template <int64_t Num, int64_t Den>
+ int64_t duration_cast() const
{
- const boost::int64_t num = period_type::num * Den;
- const boost::int64_t den = period_type::den * Num;
+ const int64_t num1 = period_type::num / gcd<period_type::num, Num>::value;
+ const int64_t num2 = Num / gcd<period_type::num, Num>::value;
+
+ const int64_t den1 = period_type::den / gcd<period_type::den, Den>::value;
+ const int64_t den2 = Den / gcd<period_type::den, Den>::value;
+
+ const int64_t num = num1 * den2;
+ const int64_t den = num2 * den1;
if (num == 1 && den == 1)
return ticks();