]> 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
update sources to ceph Nautilus 14.2.1
[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
18 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS && ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
19
20 boost::mutex m1;
21 boost::mutex m2;
22 boost::mutex m3;
23
24
25 #if defined BOOST_THREAD_USES_CHRONO
26
27 typedef boost::chrono::system_clock Clock;
28 typedef Clock::time_point time_point;
29 typedef Clock::duration duration;
30 typedef boost::chrono::milliseconds ms;
31 typedef boost::chrono::nanoseconds ns;
32 #else
33 #endif
34
35 #ifdef BOOST_THREAD_PLATFORM_WIN32
36 const ms max_diff(250);
37 #else
38 const ms max_diff(75);
39 #endif
40
41 void f()
42 {
43 #if defined BOOST_THREAD_USES_CHRONO
44 time_point t0 = Clock::now();
45 time_point t1;
46 {
47 auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_;
48 t1 = Clock::now();
49 }
50 ns d = t1 - t0 - ms(250);
51 BOOST_TEST(d < max_diff);
52 #else
53 //time_point t0 = Clock::now();
54 //time_point t1;
55 {
56 auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_;
57 //t1 = Clock::now();
58 }
59 //ns d = t1 - t0 - ms(250);
60 //BOOST_TEST(d < max_diff);
61 #endif
62 }
63
64 int main()
65 {
66 m1.lock();
67 m2.lock();
68 m3.lock();
69 boost::thread t(f);
70 #if defined BOOST_THREAD_USES_CHRONO
71 boost::this_thread::sleep_for(ms(250));
72 #else
73 #endif
74 m1.unlock();
75 m2.unlock();
76 m3.unlock();
77 t.join();
78
79 return boost::report_errors();
80 }
81 #else
82 int main()
83 {
84 return boost::report_errors();
85 }
86 #endif
87