]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> | |
92f5a8d4 | 19 | #include "../../../../timming.hpp" |
7c673cae FG |
20 | |
21 | #ifdef BOOST_THREAD_USES_CHRONO | |
22 | typedef boost::chrono::high_resolution_clock Clock; | |
23 | typedef Clock::time_point time_point; | |
24 | typedef Clock::duration duration; | |
25 | typedef boost::chrono::milliseconds ms; | |
26 | typedef boost::chrono::nanoseconds ns; | |
92f5a8d4 TL |
27 | time_point t0; |
28 | time_point t1; | |
7c673cae FG |
29 | #endif |
30 | ||
31 | boost::mutex m; | |
32 | ||
33 | #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 | |
34 | ||
92f5a8d4 | 35 | const ms max_diff(BOOST_THREAD_TEST_TIME_MS); |
11fdf7f2 | 36 | |
7c673cae FG |
37 | void f() |
38 | { | |
92f5a8d4 | 39 | t0 = Clock::now(); |
7c673cae FG |
40 | boost::unique_lock<boost::mutex> lg(m); |
41 | { | |
42 | const auto&& nlg = boost::make_nested_strict_lock(lg); (void)nlg; | |
43 | t1 = Clock::now(); | |
44 | } | |
7c673cae FG |
45 | } |
46 | #endif | |
47 | ||
48 | int main() | |
49 | { | |
50 | ||
92f5a8d4 | 51 | #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 |
7c673cae FG |
52 | { |
53 | m.lock(); | |
54 | boost::thread t(f); | |
92f5a8d4 | 55 | time_point t2 = Clock::now(); |
7c673cae | 56 | boost::this_thread::sleep_for(ms(250)); |
92f5a8d4 | 57 | time_point t3 = Clock::now(); |
7c673cae FG |
58 | m.unlock(); |
59 | t.join(); | |
92f5a8d4 TL |
60 | |
61 | ns sleep_time = t3 - t2; | |
62 | ns d_ns = t1 - t0 - sleep_time; | |
63 | ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns); | |
64 | // BOOST_TEST_GE(d_ms.count(), 0); | |
65 | BOOST_THREAD_TEST_IT(d_ms, max_diff); | |
66 | BOOST_THREAD_TEST_IT(d_ns, ns(max_diff)); | |
7c673cae FG |
67 | } |
68 | #endif | |
69 | return boost::report_errors(); | |
70 | } |