]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_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_lock_mutex_pass.cpp
CommitLineData
7c673cae
FG
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/detail/config.hpp>
14#include <boost/thread/lock_factories.hpp>
15#include <boost/thread/mutex.hpp>
16#include <boost/thread/thread.hpp>
17#include <boost/detail/lightweight_test.hpp>
18
19//#if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
20
21boost::mutex m;
22
23#if defined BOOST_THREAD_USES_CHRONO
24
25typedef boost::chrono::system_clock Clock;
26typedef Clock::time_point time_point;
27typedef Clock::duration duration;
28typedef boost::chrono::milliseconds ms;
29typedef boost::chrono::nanoseconds ns;
30#else
31#endif
32
11fdf7f2
TL
33#ifdef BOOST_THREAD_PLATFORM_WIN32
34const ms max_diff(250);
35#else
36const ms max_diff(75);
37#endif
38
7c673cae
FG
39void f()
40{
41#if defined BOOST_THREAD_USES_CHRONO
42 time_point t0 = Clock::now();
43 time_point t1;
44 {
45#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
46 auto
47#else
48 boost::unique_lock<boost::mutex>
49#endif
50 //&&
51 _ = boost::make_unique_lock(m); (void)_;
52 t1 = Clock::now();
53 }
54 ns d = t1 - t0 - ms(250);
11fdf7f2 55 BOOST_TEST(d < max_diff);
7c673cae
FG
56#else
57 //time_point t0 = Clock::now();
58 //time_point t1;
59 {
60#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
61 auto
62#else
63 boost::unique_lock<boost::mutex>
64#endif
65 //&&
66 _ = boost::make_unique_lock(m); (void)_;
67 //t1 = Clock::now();
68 }
69 //ns d = t1 - t0 - ms(250);
11fdf7f2 70 //BOOST_TEST(d < max_diff);
7c673cae
FG
71#endif
72}
73
74int main()
75{
76 m.lock();
77 boost::thread t(f);
78#if defined BOOST_THREAD_USES_CHRONO
79 boost::this_thread::sleep_for(ms(250));
80#else
81#endif
82 m.unlock();
83 t.join();
84
85 return boost::report_errors();
86}
87//#else
88//int main()
89//{
90// return boost::report_errors();
91//}
92//#endif
93