]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/named_sharable_mutex_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / interprocess / test / named_sharable_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 "mutex_test_template.hpp"
12 #include "sharable_mutex_test_template.hpp"
13 #include "named_creation_template.hpp"
14 #include <boost/interprocess/sync/named_sharable_mutex.hpp>
15 #include <string>
16 #include "get_process_id_name.hpp"
17
18 using namespace boost::interprocess;
19
20 struct mutex_deleter
21 {
22 ~mutex_deleter()
23 { named_sharable_mutex::remove(test::get_process_id_name()); }
24 };
25
26 //This wrapper is necessary to have a default constructor
27 //in generic mutex_test_template functions
28 class named_sharable_mutex_lock_test_wrapper
29 : public named_sharable_mutex
30 {
31 public:
32 named_sharable_mutex_lock_test_wrapper()
33 : named_sharable_mutex(open_or_create, test::get_process_id_name())
34 { ++count_; }
35
36 ~named_sharable_mutex_lock_test_wrapper()
37 {
38 if(--count_){
39 ipcdetail::interprocess_tester::
40 dont_close_on_destruction(static_cast<named_sharable_mutex&>(*this));
41 }
42 }
43
44 static int count_;
45 };
46
47 int named_sharable_mutex_lock_test_wrapper::count_ = 0;
48
49
50 //This wrapper is necessary to have a common constructor
51 //in generic named_creation_template functions
52 class named_sharable_mutex_creation_test_wrapper
53 : public mutex_deleter, public named_sharable_mutex
54 {
55 public:
56 named_sharable_mutex_creation_test_wrapper
57 (create_only_t)
58 : named_sharable_mutex(create_only, test::get_process_id_name())
59 { ++count_; }
60
61 named_sharable_mutex_creation_test_wrapper
62 (open_only_t)
63 : named_sharable_mutex(open_only, test::get_process_id_name())
64 { ++count_; }
65
66 named_sharable_mutex_creation_test_wrapper
67 (open_or_create_t)
68 : named_sharable_mutex(open_or_create, test::get_process_id_name())
69 { ++count_; }
70
71 ~named_sharable_mutex_creation_test_wrapper()
72 {
73 if(--count_){
74 ipcdetail::interprocess_tester::
75 dont_close_on_destruction(static_cast<named_sharable_mutex&>(*this));
76 }
77 }
78
79 static int count_;
80 };
81
82 int named_sharable_mutex_creation_test_wrapper::count_ = 0;
83
84 int main ()
85 {
86 try{
87 named_sharable_mutex::remove(test::get_process_id_name());
88 test::test_named_creation< test::named_sync_creation_test_wrapper<named_sharable_mutex> >();
89 test::test_all_lock< test::named_sync_wrapper<named_sharable_mutex> >();
90 test::test_all_mutex<test::named_sync_wrapper<named_sharable_mutex> >();
91 test::test_all_sharable_mutex<test::named_sync_wrapper<named_sharable_mutex> >();
92 }
93 catch(std::exception &ex){
94 named_sharable_mutex::remove(test::get_process_id_name());
95 std::cout << ex.what() << std::endl;
96 return 1;
97 }
98 named_sharable_mutex::remove(test::get_process_id_name());
99 return 0;
100 }