]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_locks_mutex_pass.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / locks / unique_lock / cons / make_unique_locks_mutex_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/lock_factories.hpp>
7
8 // template <class Mutex>
9 // unique_lock<Mutex> make_unique_lock(Mutex&);
10
11 #define BOOST_THREAD_VERSION 4
12
13 #include <boost/thread/lock_factories.hpp>
14 #include <boost/thread/mutex.hpp>
15 #include <boost/thread/thread.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17 #include "../../../../../timming.hpp"
18
19 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS && ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
20
21 boost::mutex m1;
22 boost::mutex m2;
23 boost::mutex m3;
24
25
26 #if defined BOOST_THREAD_USES_CHRONO
27
28 typedef boost::chrono::high_resolution_clock Clock;
29 typedef Clock::time_point time_point;
30 typedef Clock::duration duration;
31 typedef boost::chrono::milliseconds ms;
32 typedef boost::chrono::nanoseconds ns;
33 time_point t0;
34 time_point t1;
35 #else
36 #endif
37
38 const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
39
40 void f()
41 {
42 #if defined BOOST_THREAD_USES_CHRONO
43 t0 = Clock::now();
44 {
45 auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_;
46 t1 = Clock::now();
47 }
48 #else
49 //time_point t0 = Clock::now();
50 //time_point t1;
51 {
52 auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_;
53 //t1 = Clock::now();
54 }
55 //ns d = t1 - t0 - ms(250);
56 //BOOST_TEST(d < max_diff);
57 #endif
58 }
59
60 int main()
61 {
62 m1.lock();
63 m2.lock();
64 m3.lock();
65 boost::thread t(f);
66 #if defined BOOST_THREAD_USES_CHRONO
67 time_point t2 = Clock::now();
68 boost::this_thread::sleep_for(ms(250));
69 time_point t3 = Clock::now();
70 #else
71 #endif
72 m1.unlock();
73 m2.unlock();
74 m3.unlock();
75 t.join();
76
77 #if defined BOOST_THREAD_USES_CHRONO
78 ns sleep_time = t3 - t2;
79 ns d_ns = t1 - t0 - sleep_time;
80 ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
81 // BOOST_TEST_GE(d_ms.count(), 0);
82 BOOST_THREAD_TEST_IT(d_ms, max_diff);
83 BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
84 #endif
85
86 return boost::report_errors();
87 }
88 #else
89 int main()
90 {
91 return boost::report_errors();
92 }
93 #endif
94