]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/data_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / interprocess / test / data_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 <boost/interprocess/allocators/allocator.hpp>
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/containers/vector.hpp>
15 #include <boost/interprocess/containers/list.hpp>
16 #include <functional>
17 #include <string>
18 #include "print_container.hpp"
19 #include "get_process_id_name.hpp"
20
21 using namespace boost::interprocess;
22
23 int main ()
24 {
25 const int memsize = 65536;
26 std::string process_name;
27 test::get_process_id_name(process_name);
28 const char *const shMemName = process_name.c_str();
29
30 try{
31 shared_memory_object::remove(shMemName);
32
33 //Create shared memory
34 managed_shared_memory segment(create_only, shMemName, memsize);
35
36 //STL compatible allocator object, uses allocate(), deallocate() functions
37 typedef allocator<int, managed_shared_memory::segment_manager>
38 shmem_allocator_int_t;
39
40 const shmem_allocator_int_t myallocator (segment.get_segment_manager());
41
42 const int max = 100;
43 void *array[max];
44
45 const char *allocName = "testAllocation";
46
47 typedef boost::interprocess::vector<int, shmem_allocator_int_t > MyVect;
48
49 //---- ALLOC, NAMED_ALLOC, NAMED_NEW TEST ----//
50 {
51 int i;
52 //Let's allocate some memory
53 for(i = 0; i < max; ++i){
54 array[i] = segment.allocate(i+1);
55 }
56
57 //Deallocate allocated memory
58 for(i = 0; i < max; ++i){
59 segment.deallocate(array[i]);
60 }
61
62 bool res;
63
64 MyVect *shmem_vect;
65
66 //Construct and find
67 shmem_vect = segment.construct<MyVect> (allocName) (myallocator);
68 res = (shmem_vect == segment.find<MyVect>(allocName).first);
69 if(!res)
70 return 1;
71 //Destroy and check it is not present
72 segment.destroy<MyVect> (allocName);
73 res = (0 == segment.find<MyVect>(allocName).first);
74 if(!res)
75 return 1;
76
77 //Construct, dump to a file
78 shmem_vect = segment.construct<MyVect> (allocName) (myallocator);
79
80 if(shmem_vect != segment.find<MyVect>(allocName).first)
81 return 1;
82 //Destroy and check it is not present
83 segment.destroy<MyVect> (allocName);
84 res = (0 == segment.find<MyVect>(allocName).first);
85 if(!res)
86 return 1;
87 }
88 }
89 catch(...){
90 shared_memory_object::remove(shMemName);
91 throw;
92 }
93 shared_memory_object::remove(shMemName);
94 return 0;
95 }
96
97 #include <boost/interprocess/detail/config_end.hpp>