]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / test / sync / mutual_exclusion / locks / unique_lock / locking / unlock_pass.cpp
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 unique_lock;
18
19 // bool unlock();
20
21 #include <boost/thread/lock_types.hpp>
22 //#include <boost/thread/mutex.hpp>
23 #include <boost/detail/lightweight_test.hpp>
24
25
26 bool unlock_called = false;
27
28 struct mutex
29 {
30 void lock()
31 {
32 }
33 void unlock()
34 {
35 unlock_called = true;
36 }
37 };
38
39 mutex m;
40
41 int main()
42 {
43 boost::unique_lock<mutex> lk(m);
44 lk.unlock();
45 BOOST_TEST(unlock_called == true);
46 BOOST_TEST(lk.owns_lock() == false);
47 try
48 {
49 lk.unlock();
50 BOOST_TEST(false);
51 }
52 catch (boost::system::system_error& e)
53 {
54 BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
55 }
56 lk.release();
57 try
58 {
59 lk.unlock();
60 BOOST_TEST(false);
61 }
62 catch (boost::system::system_error& e)
63 {
64 BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
65 }
66
67 return boost::report_errors();
68 }
69