]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/named_upgradable_mutex_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / interprocess / test / named_upgradable_mutex_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #include <boost/interprocess/detail/config_begin.hpp>
12 #include "mutex_test_template.hpp"
13 #include "sharable_mutex_test_template.hpp"
14 #include "named_creation_template.hpp"
15 #include <boost/interprocess/sync/named_upgradable_mutex.hpp>
16 #include <string>
17 #include "get_process_id_name.hpp"
18
19 using namespace boost::interprocess;
20
21 struct mutex_deleter
22 {
23 ~mutex_deleter()
24 { named_upgradable_mutex::remove(test::get_process_id_name()); }
25 };
26
27 //This wrapper is necessary to have a default constructor
28 //in generic mutex_test_template functions
29 class named_upgradable_mutex_lock_test_wrapper
30 : public named_upgradable_mutex
31 {
32 public:
33 named_upgradable_mutex_lock_test_wrapper()
34 : named_upgradable_mutex(open_or_create, test::get_process_id_name())
35 { ++count_; }
36
37 ~named_upgradable_mutex_lock_test_wrapper()
38 {
39 if(--count_){
40 ipcdetail::interprocess_tester::
41 dont_close_on_destruction(static_cast<named_upgradable_mutex&>(*this));
42 }
43 }
44
45 static int count_;
46 };
47
48 int named_upgradable_mutex_lock_test_wrapper::count_ = 0;
49
50
51 //This wrapper is necessary to have a common constructor
52 //in generic named_creation_template functions
53 class named_upgradable_mutex_creation_test_wrapper
54 : public mutex_deleter, public named_upgradable_mutex
55 {
56 public:
57 named_upgradable_mutex_creation_test_wrapper
58 (create_only_t)
59 : named_upgradable_mutex(create_only, test::get_process_id_name())
60 { ++count_; }
61
62 named_upgradable_mutex_creation_test_wrapper
63 (open_only_t)
64 : named_upgradable_mutex(open_only, test::get_process_id_name())
65 { ++count_; }
66
67 named_upgradable_mutex_creation_test_wrapper
68 (open_or_create_t)
69 : named_upgradable_mutex(open_or_create, test::get_process_id_name())
70 { ++count_; }
71
72 ~named_upgradable_mutex_creation_test_wrapper()
73 {
74 if(--count_){
75 ipcdetail::interprocess_tester::
76 dont_close_on_destruction(static_cast<named_upgradable_mutex&>(*this));
77 }
78 }
79
80 static int count_;
81 };
82
83 int named_upgradable_mutex_creation_test_wrapper::count_ = 0;
84
85 int main ()
86 {
87 try{
88 named_upgradable_mutex::remove(test::get_process_id_name());
89 test::test_named_creation< test::named_sync_creation_test_wrapper<named_upgradable_mutex> >();
90 test::test_all_lock< test::named_sync_wrapper<named_upgradable_mutex> >();
91 test::test_all_mutex<test::named_sync_wrapper<named_upgradable_mutex> >();
92 test::test_all_sharable_mutex<test::named_sync_wrapper<named_upgradable_mutex> >();
93 }
94 catch(std::exception &ex){
95 named_upgradable_mutex::remove(test::get_process_id_name());
96 std::cout << ex.what() << std::endl;
97 return 1;
98 }
99 named_upgradable_mutex::remove(test::get_process_id_name());
100 return 0;
101 }
102
103 #include <boost/interprocess/detail/config_end.hpp>