1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // Copyright (C) 2011 Vicente J. Botet Escriba
11 //
12 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
13 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14 
15 // <boost/thread/null_mutex.hpp>
16 
17 // class null_mutex;
18 
19 // bool try_lock();
20 
21 #include <boost/thread/null_mutex.hpp>
22 #include <boost/thread/thread.hpp>
23 #include <boost/detail/lightweight_test.hpp>
24 #include "../../../timming.hpp"
25 
26 
27 
28 boost::null_mutex m;
29 
30 #if defined BOOST_THREAD_USES_CHRONO
31 typedef boost::chrono::high_resolution_clock Clock;
32 typedef Clock::time_point time_point;
33 typedef Clock::duration duration;
34 typedef boost::chrono::milliseconds ms;
35 typedef boost::chrono::nanoseconds ns;
36 #else
37 #endif
38 
39 const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
40 
f()41 void f()
42 {
43 #if defined BOOST_THREAD_USES_CHRONO
44   time_point t0 = Clock::now();
45   BOOST_TEST(m.try_lock());
46   time_point t1 = Clock::now();
47   BOOST_TEST(m.try_lock());
48   m.unlock();
49   m.unlock();
50   ns d = t1 - t0;
51   BOOST_THREAD_TEST_IT(d, ns(max_diff));
52 #else
53   BOOST_TEST(m.try_lock());
54   BOOST_TEST(m.try_lock());
55   m.unlock();
56   m.unlock();
57 #endif
58 }
59 
main()60 int main()
61 {
62   m.lock();
63   boost::thread t(f);
64   m.unlock();
65   t.join();
66 
67   return boost::report_errors();
68 }
69 
70 
71