]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/memory_algorithm_test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / interprocess / test / memory_algorithm_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-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 <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
14 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
15 #include <boost/interprocess/indexes/null_index.hpp>
16 #include <boost/interprocess/sync/mutex_family.hpp>
17 #include <boost/interprocess/detail/type_traits.hpp>
18 #include <boost/move/detail/type_traits.hpp> //make_unsigned, alignment_of
19 #include "memory_algorithm_test_template.hpp"
20 #include <iostream>
21 #include <string>
22 #include "get_process_id_name.hpp"
23
24 using namespace boost::interprocess;
25
26 const int Memsize = 16384;
27 const char *const shMemName = test::get_process_id_name();
28
29 int test_simple_seq_fit()
30 {
31 //A shared memory with simple sequential fit algorithm
32 typedef basic_managed_shared_memory
33 <char
34 ,simple_seq_fit<mutex_family>
35 ,null_index
36 > my_managed_shared_memory;
37
38 //Create shared memory
39 shared_memory_object::remove(shMemName);
40 my_managed_shared_memory segment(create_only, shMemName, Memsize);
41
42 //Now take the segment manager and launch memory test
43 if(!test::test_all_allocation(*segment.get_segment_manager())){
44 return 1;
45 }
46 return 0;
47 }
48
49 template<std::size_t Alignment>
50 int test_rbtree_best_fit()
51 {
52 //A shared memory with red-black tree best fit algorithm
53 typedef basic_managed_shared_memory
54 <char
55 ,rbtree_best_fit<mutex_family, offset_ptr<void>, Alignment>
56 ,null_index
57 > my_managed_shared_memory;
58
59 //Create shared memory
60 shared_memory_object::remove(shMemName);
61 my_managed_shared_memory segment(create_only, shMemName, Memsize);
62
63 //Now take the segment manager and launch memory test
64 if(!test::test_all_allocation(*segment.get_segment_manager())){
65 return 1;
66 }
67 return 0;
68 }
69
70 int main ()
71 {
72 const std::size_t void_ptr_align = ::boost::container::dtl::alignment_of<offset_ptr<void> >::value;
73
74 if(test_simple_seq_fit()){
75 return 1;
76 }
77 if(test_rbtree_best_fit<void_ptr_align>()){
78 return 1;
79 }
80 if(test_rbtree_best_fit<2*void_ptr_align>()){
81 return 1;
82 }
83 if(test_rbtree_best_fit<4*void_ptr_align>()){
84 return 1;
85 }
86
87 shared_memory_object::remove(shMemName);
88 return 0;
89 }
90
91 #include <boost/interprocess/detail/config_end.hpp>