]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / recursive_timed_mutex / lock_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/recursive_mutex.hpp>
16
17// class recursive_timed_mutex;
18
19// void lock();
20
21#include <boost/thread/recursive_mutex.hpp>
22#include <boost/thread/thread.hpp>
23#include <boost/detail/lightweight_test.hpp>
11fdf7f2 24#include <iostream>
7c673cae
FG
25
26boost::recursive_timed_mutex m;
27
28#if defined BOOST_THREAD_USES_CHRONO
29typedef boost::chrono::system_clock Clock;
30typedef Clock::time_point time_point;
31typedef Clock::duration duration;
32typedef boost::chrono::milliseconds ms;
33typedef boost::chrono::nanoseconds ns;
34#else
35#endif
36
11fdf7f2
TL
37#ifdef BOOST_THREAD_PLATFORM_WIN32
38const ms max_diff(250);
39#else
40const ms max_diff(75);
41#endif
42
7c673cae
FG
43void f()
44{
45#if defined BOOST_THREAD_USES_CHRONO
46 time_point t0 = Clock::now();
47 m.lock();
48 time_point t1 = Clock::now();
49 m.lock();
50 m.unlock();
51 m.unlock();
52 ns d = t1 - t0 - ms(250);
11fdf7f2
TL
53 std::cout << "diff= " << d.count() << std::endl;
54 std::cout << "max_diff= " << max_diff.count() << std::endl;
55 BOOST_TEST(d < max_diff);
7c673cae
FG
56#else
57 //time_point t0 = Clock::now();
58 m.lock();
59 //time_point t1 = Clock::now();
60 m.lock();
61 m.unlock();
62 m.unlock();
63 //ns d = t1 - t0 - ms(250);
11fdf7f2 64 //BOOST_TEST(d < max_diff);
7c673cae
FG
65#endif
66}
67
68int main()
69{
70 m.lock();
71 boost::thread t(f);
72#if defined BOOST_THREAD_USES_CHRONO
73 boost::this_thread::sleep_for(ms(250));
74#else
75#endif
76 m.unlock();
77 t.join();
78
79 return boost::report_errors();
80}
81
82