1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Copyright (C) 2011 Vicente J. Botet Escriba
11 // Distributed under the Boost Software License, Version 1.0. (See accompanying
12 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14 // <boost/thread/condition_variable>
16 // class condition_variable;
18 // condition_variable(const condition_variable&) = delete;
20 #include <boost/thread/condition_variable.hpp>
21 #include <boost/thread/mutex.hpp>
22 #include <boost/thread/thread.hpp>
23 #include <boost/detail/lightweight_test.hpp>
26 #include "../../../timming.hpp"
28 #if defined BOOST_THREAD_USES_CHRONO
29 typedef boost::chrono::milliseconds milliseconds
;
30 typedef boost::chrono::nanoseconds nanoseconds
;
31 typedef boost::chrono::milliseconds ms
;
32 typedef boost::chrono::nanoseconds ns
;
35 typedef boost::chrono::milliseconds duration
;
36 typedef duration::rep rep
;
37 typedef duration::period period
;
38 typedef boost::chrono::time_point
<Clock
> time_point
;
39 static const bool is_steady
= true;
41 static time_point
now()
43 using namespace boost::chrono
;
44 return time_point(duration_cast
<duration
> (steady_clock::now().time_since_epoch()));
52 explicit Pred(int& i
) :
63 boost::condition_variable cv
;
71 const ms
max_diff(BOOST_THREAD_TEST_TIME_MS
);
76 boost::unique_lock
<boost::mutex
> lk(mut
);
80 Clock::time_point t0
= Clock::now();
81 Clock::time_point t
= t0
+ Clock::duration(250);
82 bool r
= cv
.wait_until(lk
, t
, Pred(test2
));
83 Clock::time_point t1
= Clock::now();
86 assert(t1
- t0
< max_diff
);
92 const nanoseconds d
= t1
- t0
- milliseconds(250);
93 std::cout
<< "diff= " << d
.count() << std::endl
;
94 std::cout
<< "max_diff= " << max_diff
.count() << std::endl
;
101 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
110 boost::unique_lock
<boost::mutex
> lk(mut
);
112 BOOST_TEST(test1
== 0);
115 BOOST_TEST(test1
!= 0);
122 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
128 boost::unique_lock
<boost::mutex
> lk(mut
);
130 BOOST_TEST(test1
== 0);
133 BOOST_TEST(test1
!= 0);
138 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
141 return boost::report_errors();
145 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"