]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/conditions/condition_variable/wait_until_pred_pass.cpp
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>
27 #if defined BOOST_THREAD_USES_CHRONO
31 typedef boost::chrono::milliseconds duration
;
32 typedef duration::rep rep
;
33 typedef duration::period period
;
34 typedef boost::chrono::time_point
<Clock
> time_point
;
35 static const bool is_steady
= true;
37 static time_point
now()
39 using namespace boost::chrono
;
40 return time_point(duration_cast
<duration
> (steady_clock::now().time_since_epoch()));
48 explicit Pred(int& i
) :
59 boost::condition_variable cv
;
70 boost::unique_lock
<boost::mutex
> lk(mut
);
74 Clock::time_point t0
= Clock::now();
75 Clock::time_point t
= t0
+ Clock::duration(250);
76 bool r
= cv
.wait_until(lk
, t
, Pred(test2
));
78 Clock::time_point t1
= Clock::now();
81 assert(t1
- t0
< Clock::duration(250));
87 assert(t1
- t0
- Clock::duration(250) < Clock::duration(250+2));
93 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
102 boost::unique_lock
<boost::mutex
> lk(mut
);
104 BOOST_TEST(test1
== 0);
107 BOOST_TEST(test1
!= 0);
114 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
120 boost::unique_lock
<boost::mutex
> lk(mut
);
122 BOOST_TEST(test1
== 0);
125 BOOST_TEST(test1
!= 0);
130 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
133 return boost::report_errors();
137 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"