]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | boost::mutex m; | |
22 | ||
23 | #if defined BOOST_THREAD_USES_CHRONO | |
24 | ||
25 | typedef boost::chrono::system_clock Clock; | |
26 | typedef Clock::time_point time_point; | |
27 | typedef Clock::duration duration; | |
28 | typedef boost::chrono::milliseconds ms; | |
29 | typedef boost::chrono::nanoseconds ns; | |
30 | #else | |
31 | #endif | |
32 | ||
11fdf7f2 TL |
33 | #ifdef BOOST_THREAD_PLATFORM_WIN32 |
34 | const ms max_diff(250); | |
35 | #else | |
36 | const ms max_diff(75); | |
37 | #endif | |
38 | ||
7c673cae FG |
39 | void 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 | ||
74 | int 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 |