• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_upgradable_mutex.hpp>
15 #include <string>
16 #include "get_process_id_name.hpp"
17 
18 using namespace boost::interprocess;
19 
20 struct mutex_deleter
21 {
~mutex_deletermutex_deleter22    ~mutex_deleter()
23    {  named_upgradable_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_upgradable_mutex_lock_test_wrapper
29    : public named_upgradable_mutex
30 {
31    public:
named_upgradable_mutex_lock_test_wrapper()32    named_upgradable_mutex_lock_test_wrapper()
33       :  named_upgradable_mutex(open_or_create, test::get_process_id_name())
34    {  ++count_;   }
35 
~named_upgradable_mutex_lock_test_wrapper()36    ~named_upgradable_mutex_lock_test_wrapper()
37    {
38       if(--count_){
39          ipcdetail::interprocess_tester::
40             dont_close_on_destruction(static_cast<named_upgradable_mutex&>(*this));
41       }
42    }
43 
44    static int count_;
45 };
46 
47 int named_upgradable_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_upgradable_mutex_creation_test_wrapper
53    : public mutex_deleter, public named_upgradable_mutex
54 {
55    public:
named_upgradable_mutex_creation_test_wrapper(create_only_t)56    named_upgradable_mutex_creation_test_wrapper
57       (create_only_t)
58       :  named_upgradable_mutex(create_only, test::get_process_id_name())
59    {  ++count_;   }
60 
named_upgradable_mutex_creation_test_wrapper(open_only_t)61    named_upgradable_mutex_creation_test_wrapper
62       (open_only_t)
63       :  named_upgradable_mutex(open_only, test::get_process_id_name())
64    {  ++count_;   }
65 
named_upgradable_mutex_creation_test_wrapper(open_or_create_t)66    named_upgradable_mutex_creation_test_wrapper
67       (open_or_create_t)
68       :  named_upgradable_mutex(open_or_create, test::get_process_id_name())
69    {  ++count_;   }
70 
~named_upgradable_mutex_creation_test_wrapper()71    ~named_upgradable_mutex_creation_test_wrapper()
72    {
73       if(--count_){
74          ipcdetail::interprocess_tester::
75             dont_close_on_destruction(static_cast<named_upgradable_mutex&>(*this));
76       }
77    }
78 
79    static int count_;
80 };
81 
82 int named_upgradable_mutex_creation_test_wrapper::count_ = 0;
83 
main()84 int main ()
85 {
86    try{
87       named_upgradable_mutex::remove(test::get_process_id_name());
88       test::test_named_creation< test::named_sync_creation_test_wrapper<named_upgradable_mutex> >();
89       test::test_all_lock< test::named_sync_wrapper<named_upgradable_mutex> >();
90       test::test_all_mutex<test::named_sync_wrapper<named_upgradable_mutex> >();
91       test::test_all_sharable_mutex<test::named_sync_wrapper<named_upgradable_mutex> >();
92    }
93    catch(std::exception &ex){
94       named_upgradable_mutex::remove(test::get_process_id_name());
95       std::cout << ex.what() << std::endl;
96       return 1;
97    }
98    named_upgradable_mutex::remove(test::get_process_id_name());
99    return 0;
100 }
101