]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/default_pass.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / locks / nested_strict_lock / default_pass.cpp
1 // Copyright (C) 2012 Vicente J. Botet Escriba
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // <boost/thread/locks.hpp>
7
8 // template <class Mutex> class nested_strict_lock;
9
10 // nested_strict_lock(Mutex &);
11
12 #include <boost/thread/lock_types.hpp>
13 #include <boost/thread/strict_lock.hpp>
14 #include <boost/thread/mutex.hpp>
15 #include <boost/thread/thread.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17
18 #ifdef BOOST_THREAD_USES_CHRONO
19 typedef boost::chrono::high_resolution_clock Clock;
20 typedef Clock::time_point time_point;
21 typedef Clock::duration duration;
22 typedef boost::chrono::milliseconds ms;
23 typedef boost::chrono::nanoseconds ns;
24 #endif
25
26 boost::mutex m;
27
28 void f()
29 {
30 #ifdef BOOST_THREAD_USES_CHRONO
31 time_point t0 = Clock::now();
32 time_point t1;
33 boost::unique_lock<boost::mutex> lg(m);
34 {
35 boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg);
36 t1 = Clock::now();
37 }
38 ns d = t1 - t0 - ms(250);
39 // This test is spurious as it depends on the time the thread system switches the threads
40 BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
41 #else
42 //time_point t0 = Clock::now();
43 //time_point t1;
44 boost::unique_lock<boost::mutex> lg(m);
45 {
46 boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg);
47 //t1 = Clock::now();
48 }
49 //ns d = t1 - t0 - ms(250);
50 // This test is spurious as it depends on the time the thread system switches the threads
51 //BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
52 #endif
53 }
54
55 int main()
56 {
57 {
58 m.lock();
59 boost::thread t(f);
60 #ifdef BOOST_THREAD_USES_CHRONO
61 boost::this_thread::sleep_for(ms(250));
62 #endif
63 m.unlock();
64 t.join();
65 }
66
67 return boost::report_errors();
68 }