]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/futures/shared_future/wait_until_pass.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / thread / test / sync / futures / shared_future / wait_until_pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // Copyright (C) 2013 Vicente J. Botet Escriba
11 //
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14
15 // <boost/thread/future.hpp>
16
17 // class shared_future<R>
18
19 // template <class Rep, class Period>
20 // future_status
21 // wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
22
23 //#define BOOST_THREAD_VERSION 3
24 #define BOOST_THREAD_VERSION 4
25 //#define BOOST_THREAD_USES_LOG
26 #define BOOST_THREAD_USES_LOG_THREAD_ID
27 #include <boost/thread/detail/log.hpp>
28
29 #include <boost/thread/future.hpp>
30 #include <boost/thread/thread.hpp>
31 #include <boost/chrono/chrono_io.hpp>
32 #include <boost/detail/lightweight_test.hpp>
33 #include "../../../timming.hpp"
34
35 #if defined BOOST_THREAD_USES_CHRONO
36
37 #ifdef BOOST_MSVC
38 #pragma warning(disable: 4127) // conditional expression is constant
39 #endif
40
41 typedef boost::chrono::milliseconds ms;
42 typedef boost::chrono::nanoseconds ns;
43
44 namespace boost
45 {
46 template <typename OStream>
47 OStream& operator<<(OStream& os , boost::future_status st )
48 {
49 os << underlying_cast<int>(st) << " ";
50 return os;
51 }
52 }
53
54 void func1(boost::promise<int> p)
55 {
56 boost::this_thread::sleep_for(ms(500));
57 p.set_value(3);
58 }
59
60 int j = 0;
61
62 void func3(boost::promise<int&> p)
63 {
64 boost::this_thread::sleep_for(ms(500));
65 j = 5;
66 p.set_value(j);
67 }
68
69 void func5(boost::promise<void> p)
70 {
71 boost::this_thread::sleep_for(ms(500));
72 p.set_value();
73 }
74
75 const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
76
77 int main()
78 {
79 BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
80 {
81 typedef boost::chrono::high_resolution_clock Clock;
82 {
83 typedef int T;
84 boost::promise<T> p;
85 boost::shared_future<T> f((p.get_future()));
86 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
87 boost::thread(func1, boost::move(p)).detach();
88 #endif
89 BOOST_TEST(f.valid());
90 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
91 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
92 #else
93 func1(boost::move(p));
94 #endif
95 BOOST_TEST(f.valid());
96 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
97 BOOST_TEST(f.valid());
98 Clock::time_point t0 = Clock::now();
99 f.wait();
100 Clock::time_point t1 = Clock::now();
101 BOOST_TEST(f.valid());
102 ns d = t1 - t0;
103 BOOST_THREAD_TEST_IT(d, ns(max_diff));
104 }
105 {
106 typedef int& T;
107 boost::promise<T> p;
108 boost::shared_future<T> f((p.get_future()));
109 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
110 boost::thread(func3, boost::move(p)).detach();
111 #endif
112 BOOST_TEST(f.valid());
113 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
114 BOOST_TEST(f.valid());
115 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
116 #else
117 func3(boost::move(p));
118 #endif
119 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
120 BOOST_TEST(f.valid());
121 Clock::time_point t0 = Clock::now();
122 f.wait();
123 Clock::time_point t1 = Clock::now();
124 BOOST_TEST(f.valid());
125 ns d = t1 - t0;
126 BOOST_THREAD_TEST_IT(d, ns(max_diff));
127 }
128 {
129 typedef void T;
130 boost::promise<T> p;
131 boost::shared_future<T> f((p.get_future()));
132 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
133 boost::thread(func5, boost::move(p)).detach();
134 #endif
135 BOOST_TEST(f.valid());
136 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
137 BOOST_TEST(f.valid());
138 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
139 #else
140 func5(boost::move(p));
141 #endif
142 BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
143 BOOST_TEST(f.valid());
144 Clock::time_point t0 = Clock::now();
145 f.wait();
146 Clock::time_point t1 = Clock::now();
147 BOOST_TEST(f.valid());
148 ns d = t1 - t0;
149 BOOST_THREAD_TEST_IT(d, ns(max_diff));
150 }
151 }
152 BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
153
154 return boost::report_errors();
155 }
156
157 #else
158 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
159 #endif