annotate DEPENDENCIES/generic/include/boost/thread/v2/thread.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 2 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 3 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 4 // (C) Copyright 2011 Vicente J. Botet Escriba
Chris@16 5
Chris@16 6 #ifndef BOOST_THREAD_V2_THREAD_HPP
Chris@16 7 #define BOOST_THREAD_V2_THREAD_HPP
Chris@16 8
Chris@16 9 #include <boost/thread/detail/config.hpp>
Chris@16 10 #ifdef BOOST_THREAD_USES_CHRONO
Chris@16 11 #include <boost/chrono/system_clocks.hpp>
Chris@16 12 #include <boost/chrono/ceil.hpp>
Chris@16 13 #endif
Chris@16 14 #include <boost/thread/condition_variable.hpp>
Chris@16 15 #include <boost/thread/lock_types.hpp>
Chris@16 16
Chris@16 17 namespace boost
Chris@16 18 {
Chris@16 19 namespace this_thread
Chris@16 20 {
Chris@101 21 namespace no_interruption_point
Chris@101 22 {
Chris@101 23 #ifdef BOOST_THREAD_USES_CHRONO
Chris@16 24
Chris@101 25 template <class Clock, class Duration>
Chris@101 26 void sleep_until(const chrono::time_point<Clock, Duration>& t)
Chris@101 27 {
Chris@101 28 using namespace chrono;
Chris@101 29 mutex mut;
Chris@101 30 condition_variable cv;
Chris@101 31 unique_lock<mutex> lk(mut);
Chris@101 32 while (Clock::now() < t)
Chris@101 33 cv.wait_until(lk, t);
Chris@101 34 }
Chris@101 35
Chris@101 36 #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY
Chris@101 37
Chris@101 38 template <class Rep, class Period>
Chris@101 39 void sleep_for(const chrono::duration<Rep, Period>& d)
Chris@101 40 {
Chris@101 41 using namespace chrono;
Chris@101 42 if (d > duration<Rep, Period>::zero())
Chris@101 43 {
Chris@101 44 duration<long double> Max = nanoseconds::max BOOST_PREVENT_MACRO_SUBSTITUTION ();
Chris@101 45 nanoseconds ns;
Chris@101 46 if (d < Max)
Chris@101 47 {
Chris@101 48 ns = duration_cast<nanoseconds>(d);
Chris@101 49 if (ns < d)
Chris@101 50 ++ns;
Chris@101 51 }
Chris@101 52 else
Chris@101 53 ns = nanoseconds:: max BOOST_PREVENT_MACRO_SUBSTITUTION ();
Chris@101 54 sleep_for(ns);
Chris@101 55 }
Chris@101 56 }
Chris@101 57
Chris@101 58 template <class Duration>
Chris@101 59 inline BOOST_SYMBOL_VISIBLE
Chris@101 60 void sleep_until(const chrono::time_point<chrono::steady_clock, Duration>& t)
Chris@101 61 {
Chris@101 62 using namespace chrono;
Chris@101 63 sleep_for(t - steady_clock::now());
Chris@101 64 }
Chris@101 65 #else
Chris@101 66 template <class Rep, class Period>
Chris@101 67 void sleep_for(const chrono::duration<Rep, Period>& d)
Chris@101 68 {
Chris@101 69 using namespace chrono;
Chris@101 70 if (d > duration<Rep, Period>::zero())
Chris@101 71 {
Chris@101 72 steady_clock::time_point c_timeout = steady_clock::now() + ceil<nanoseconds>(d);
Chris@101 73 sleep_until(c_timeout);
Chris@101 74 }
Chris@101 75 }
Chris@101 76
Chris@101 77 #endif
Chris@101 78
Chris@101 79 #endif
Chris@101 80 }
Chris@16 81 #ifdef BOOST_THREAD_USES_CHRONO
Chris@16 82
Chris@16 83 template <class Clock, class Duration>
Chris@16 84 void sleep_until(const chrono::time_point<Clock, Duration>& t)
Chris@16 85 {
Chris@16 86 using namespace chrono;
Chris@16 87 mutex mut;
Chris@16 88 condition_variable cv;
Chris@16 89 unique_lock<mutex> lk(mut);
Chris@16 90 while (Clock::now() < t)
Chris@16 91 cv.wait_until(lk, t);
Chris@16 92 }
Chris@16 93
Chris@16 94 #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY
Chris@16 95
Chris@16 96 template <class Rep, class Period>
Chris@16 97 void sleep_for(const chrono::duration<Rep, Period>& d)
Chris@16 98 {
Chris@16 99 using namespace chrono;
Chris@16 100 if (d > duration<Rep, Period>::zero())
Chris@16 101 {
Chris@16 102 duration<long double> Max = nanoseconds::max BOOST_PREVENT_MACRO_SUBSTITUTION ();
Chris@16 103 nanoseconds ns;
Chris@16 104 if (d < Max)
Chris@16 105 {
Chris@16 106 ns = duration_cast<nanoseconds>(d);
Chris@16 107 if (ns < d)
Chris@16 108 ++ns;
Chris@16 109 }
Chris@16 110 else
Chris@16 111 ns = nanoseconds:: max BOOST_PREVENT_MACRO_SUBSTITUTION ();
Chris@16 112 sleep_for(ns);
Chris@16 113 }
Chris@16 114 }
Chris@16 115
Chris@16 116 template <class Duration>
Chris@16 117 inline BOOST_SYMBOL_VISIBLE
Chris@16 118 void sleep_until(const chrono::time_point<chrono::steady_clock, Duration>& t)
Chris@16 119 {
Chris@16 120 using namespace chrono;
Chris@16 121 sleep_for(t - steady_clock::now());
Chris@16 122 }
Chris@16 123 #else
Chris@16 124 template <class Rep, class Period>
Chris@16 125 void sleep_for(const chrono::duration<Rep, Period>& d)
Chris@16 126 {
Chris@16 127 using namespace chrono;
Chris@16 128 if (d > duration<Rep, Period>::zero())
Chris@16 129 {
Chris@16 130 steady_clock::time_point c_timeout = steady_clock::now() + ceil<nanoseconds>(d);
Chris@16 131 sleep_until(c_timeout);
Chris@16 132 }
Chris@16 133 }
Chris@16 134
Chris@16 135 #endif
Chris@16 136
Chris@16 137 #endif
Chris@16 138 }
Chris@16 139 }
Chris@16 140
Chris@16 141
Chris@16 142 #endif