]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / null_mutex / try_lock_for_pass.cpp
CommitLineData
7c673cae
FG
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// template <class Rep, class Period>
20// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
21
22#include <boost/thread/null_mutex.hpp>
23#include <boost/thread/thread.hpp>
24#include <boost/detail/lightweight_test.hpp>
25
26#if defined BOOST_THREAD_USES_CHRONO
27
28
29boost::null_mutex m;
30
31typedef boost::chrono::steady_clock Clock;
32typedef Clock::time_point time_point;
33typedef Clock::duration duration;
34typedef boost::chrono::milliseconds ms;
35typedef boost::chrono::nanoseconds ns;
36
11fdf7f2
TL
37#ifdef BOOST_THREAD_PLATFORM_WIN32
38const ms max_diff(250);
39#else
40const ms max_diff(50);
41#endif
42
7c673cae
FG
43void f1()
44{
45 time_point t0 = Clock::now();
11fdf7f2 46 BOOST_TEST(m.try_lock_for(ms(250)) == true);
7c673cae
FG
47 time_point t1 = Clock::now();
48 BOOST_TEST(m.try_lock());
49 m.unlock();
50 m.unlock();
51 ns d = t1 - t0 ;
11fdf7f2 52 BOOST_TEST(d < max_diff);
7c673cae
FG
53}
54
55
56int main()
57{
58 {
59 m.lock();
60 boost::thread t(f1);
61 m.unlock();
62 t.join();
63 }
64
65 return boost::report_errors();
66}
67
68#else
69#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
70#endif
71