]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/nested_strict_lock/make_nested_strict_lock_pass.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / locks / nested_strict_lock / make_nested_strict_lock_pass.cpp
1 // Copyright (C) 2011 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/strict_lock.hpp>
7
8 // template <class Lockable>
9 // strict_lock<Lockable> make_strict_lock(Lockable &);
10
11 #define BOOST_THREAD_VERSION 4
12
13 #include <boost/thread/lock_types.hpp>
14 #include <boost/thread/strict_lock.hpp>
15 #include <boost/thread/mutex.hpp>
16 #include <boost/thread/thread.hpp>
17
18 #include <boost/detail/lightweight_test.hpp>
19
20 #ifdef BOOST_THREAD_USES_CHRONO
21 typedef boost::chrono::high_resolution_clock Clock;
22 typedef Clock::time_point time_point;
23 typedef Clock::duration duration;
24 typedef boost::chrono::milliseconds ms;
25 typedef boost::chrono::nanoseconds ns;
26 #endif
27
28 boost::mutex m;
29
30 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO
31
32 #ifdef BOOST_THREAD_PLATFORM_WIN32
33 const ms max_diff(250);
34 #else
35 const ms max_diff(75);
36 #endif
37
38 void f()
39 {
40 time_point t0 = Clock::now();
41 time_point t1;
42 boost::unique_lock<boost::mutex> lg(m);
43 {
44 const auto&& nlg = boost::make_nested_strict_lock(lg); (void)nlg;
45 t1 = Clock::now();
46 }
47 ns d = t1 - t0 - ms(250);
48 BOOST_TEST(d < max_diff);
49 }
50 #endif
51
52 int main()
53 {
54
55 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK
56 {
57 m.lock();
58 boost::thread t(f);
59 boost::this_thread::sleep_for(ms(250));
60 m.unlock();
61 t.join();
62 }
63 #endif
64 return boost::report_errors();
65 }