]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / locks / upgrade_lock / locking / 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/locks.hpp>
16
17// template <class Mutex> class upgrade_lock;
18
19// template <class Rep, class Period>
20// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
21
22#include <boost/thread/lock_types.hpp>
23//#include <boost/thread/shared_mutex.hpp>
24#include <boost/detail/lightweight_test.hpp>
25
26bool try_lock_for_called = false;
27
28typedef boost::chrono::milliseconds ms;
29
30struct shared_mutex
31{
32 template <class Rep, class Period>
33 bool try_lock_upgrade_for(const boost::chrono::duration<Rep, Period>& rel_time)
34 {
35 BOOST_TEST(rel_time == ms(5));
36 try_lock_for_called = !try_lock_for_called;
37 return try_lock_for_called;
38 }
39 void unlock_upgrade()
40 {
41 }
42};
43
44shared_mutex m;
45
46int main()
47{
48 boost::upgrade_lock<shared_mutex> lk(m, boost::defer_lock);
49 BOOST_TEST(lk.try_lock_for(ms(5)) == true);
50 BOOST_TEST(try_lock_for_called == true);
51 BOOST_TEST(lk.owns_lock() == true);
52 try
53 {
54 lk.try_lock_for(ms(5));
55 BOOST_TEST(false);
56 }
57 catch (boost::system::system_error& e)
58 {
59 BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
60 }
61 lk.unlock();
62 BOOST_TEST(lk.try_lock_for(ms(5)) == false);
63 BOOST_TEST(try_lock_for_called == false);
64 BOOST_TEST(lk.owns_lock() == false);
65 lk.release();
66 try
67 {
68 lk.try_lock_for(ms(5));
69 BOOST_TEST(false);
70 }
71 catch (boost::system::system_error& e)
72 {
73 BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
74 }
75
76 return boost::report_errors();
77}
78