]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/conditions/condition_variable/wait_until_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>
25 #if defined BOOST_THREAD_USES_CHRONO
29 typedef boost::chrono::milliseconds duration
;
30 typedef duration::rep rep
;
31 typedef duration::period period
;
32 typedef boost::chrono::time_point
<Clock
> time_point
;
33 static const bool is_steady
= true;
35 static time_point
now()
37 using namespace boost::chrono
;
38 return time_point(duration_cast
<duration
> (steady_clock::now().time_since_epoch()));
42 boost::condition_variable cv
;
52 boost::unique_lock
< boost::mutex
> lk(mut
);
53 BOOST_TEST(test2
== 0);
56 Clock::time_point t0
= Clock::now();
57 Clock::time_point t
= t0
+ Clock::duration(250);
59 while (test2
== 0 && cv
.wait_until(lk
, t
) == boost::cv_status::no_timeout
)
61 Clock::time_point t1
= Clock::now();
64 BOOST_TEST(t1
- t0
< Clock::duration(250));
65 BOOST_TEST(test2
!= 0);
69 // This test is spurious as it depends on the time the thread system switches the threads
70 BOOST_TEST(t1
- t0
- Clock::duration(250) < Clock::duration(count
*250+5+1000));
71 BOOST_TEST(test2
== 0);
79 boost::unique_lock
< boost::mutex
> lk(mut
);
81 BOOST_TEST(test1
== 0);
84 BOOST_TEST(test1
!= 0);
93 boost::unique_lock
< boost::mutex
> lk(mut
);
95 BOOST_TEST(test1
== 0);
98 BOOST_TEST(test1
!= 0);
103 return boost::report_errors();
107 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"