mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Trailing spaces and Phoenix singleton for intermodule_singleton
[SVN r78515]
This commit is contained in:
@@ -43,7 +43,7 @@ doxygen autodoc
|
||||
;
|
||||
|
||||
xml interprocess : interprocess.qbk
|
||||
:
|
||||
:
|
||||
<include>../../../tools/auto_index/include
|
||||
;
|
||||
|
||||
@@ -60,26 +60,26 @@ boostbook standalone
|
||||
<dependency>autodoc
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||
# Build requirements go here:
|
||||
|
||||
|
||||
# <auto-index>on (or off) one turns on (or off) indexing:
|
||||
<auto-index>on
|
||||
|
||||
|
||||
# Turns on (or off) auto-index-verbose for diagnostic info.
|
||||
# This is highly recommended until you have got all the many details correct!
|
||||
<auto-index-verbose>on
|
||||
|
||||
<auto-index-verbose>on
|
||||
|
||||
# Choose the indexing method (separately for html and PDF) - see manual.
|
||||
# Choose indexing method for PDFs:
|
||||
<format>pdf:<auto-index-internal>off
|
||||
|
||||
|
||||
# Choose indexing method for html:
|
||||
<format>html:<auto-index-internal>on
|
||||
|
||||
|
||||
# Set the name of the script file to use (index.idx is popular):
|
||||
<auto-index-script>index.idx
|
||||
# Commands in the script file should all use RELATIVE PATHS
|
||||
# otherwise the script will not be portable to other machines.
|
||||
# Relative paths are normally taken as relative to the location
|
||||
# Relative paths are normally taken as relative to the location
|
||||
# of the script file, but we can add a prefix to all
|
||||
# those relative paths using the <auto-index-prefix> feature.
|
||||
# The path specified by <auto-index-prefix> may be either relative or
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
!scan-path "boost/interprocess" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/allocators" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/containers" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/indexes" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/ipc" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/mem_algo" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/smart_ptr" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/streams" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/sync" ".*.hpp" false
|
||||
!scan-path "boost/interprocess" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/allocators" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/containers" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/indexes" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/ipc" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/mem_algo" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/smart_ptr" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/streams" ".*.hpp" false
|
||||
!scan-path "boost/interprocess/sync" ".*.hpp" false
|
||||
|
||||
1116
doc/interprocess.qbk
1116
doc/interprocess.qbk
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,14 @@
|
||||
# Boost Interprocess Library Example Jamfile
|
||||
|
||||
# (C) Copyright Ion Gaztanaga 2006.
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Adapted from John Maddock's TR1 Jamfile.v2
|
||||
# Copyright John Maddock 2005.
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# this rule enumerates through all the sources and invokes
|
||||
@@ -25,7 +25,7 @@ rule test_all
|
||||
: # additional args
|
||||
<toolset>acc:<linkflags>-lrt
|
||||
<toolset>acc-pa_risc:<linkflags>-lrt
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<host-os>hpux,<toolset>gcc:<linkflags>"-Wl,+as,mpas"
|
||||
: # test-files
|
||||
: # requirements
|
||||
@@ -40,7 +40,7 @@ rule test_all
|
||||
: # requirements
|
||||
<toolset>acc:<linkflags>-lrt
|
||||
<toolset>acc-pa_risc:<linkflags>-lrt
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<host-os>hpux,<toolset>gcc:<linkflags>"-Wl,+as,mpas"
|
||||
] ;
|
||||
}
|
||||
@@ -48,4 +48,4 @@ rule test_all
|
||||
return $(all_rules) ;
|
||||
}
|
||||
|
||||
test-suite interprocess_example : [ test_all r ] : <threading>multi ;
|
||||
test-suite interprocess_example : [ test_all r ] : <threading>multi ;
|
||||
|
||||
@@ -46,7 +46,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only,test::get_process_id_name(), 65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -46,7 +46,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only,test::get_process_id_name(), 65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -23,7 +23,7 @@ int main ()
|
||||
|
||||
//Write all the memory to 1
|
||||
std::memset(region.get_address(), 1, region.get_size());
|
||||
|
||||
|
||||
//The segment is unmapped when "region" goes out of scope
|
||||
}
|
||||
catch(interprocess_exception &ex){
|
||||
|
||||
@@ -48,7 +48,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only,test::get_process_id_name(), 65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
@@ -64,7 +64,7 @@ int main ()
|
||||
const std::size_t BufferSize = 100*5;
|
||||
|
||||
//Allocate a buffer in shared memory to write data
|
||||
char *my_cstring =
|
||||
char *my_cstring =
|
||||
segment.construct<char>("MyCString")[BufferSize](0);
|
||||
bufferstream mybufstream(my_cstring, BufferSize);
|
||||
|
||||
@@ -82,7 +82,7 @@ int main ()
|
||||
std::istream_iterator<int> it(mybufstream), itend;
|
||||
std::copy(it, itend, std::back_inserter(data2));
|
||||
|
||||
//This extraction should have ended will fail error since
|
||||
//This extraction should have ended will fail error since
|
||||
//the numbers formatted in the buffer end before the end
|
||||
//of the buffer. (Otherwise it would trigger eofbit)
|
||||
assert(mybufstream.fail());
|
||||
@@ -93,7 +93,7 @@ int main ()
|
||||
//Clear errors and rewind
|
||||
mybufstream.clear();
|
||||
mybufstream.seekp(0, std::ios::beg);
|
||||
|
||||
|
||||
//Now write again the data trying to do a buffer overflow
|
||||
for(int i = 0, m = data.size()*5; i < m; ++i){
|
||||
mybufstream << data[i%5] << std::endl;
|
||||
|
||||
@@ -46,7 +46,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only,test::get_process_id_name(), 65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -46,7 +46,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only, test::get_process_id_name(), 65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -54,7 +54,7 @@ int main ()
|
||||
//->
|
||||
|
||||
//Alias an STL-like allocator of ints that allocates ints from the segment
|
||||
typedef allocator<int, managed_shared_memory::segment_manager>
|
||||
typedef allocator<int, managed_shared_memory::segment_manager>
|
||||
ShmemAllocator;
|
||||
|
||||
//Alias a vector that uses the previous STL-like allocator
|
||||
@@ -67,14 +67,14 @@ int main ()
|
||||
//Initialize the STL-like allocator
|
||||
const ShmemAllocator alloc_inst (segment.get_segment_manager());
|
||||
|
||||
//Construct the vector in the shared memory segment with the STL-like allocator
|
||||
//Construct the vector in the shared memory segment with the STL-like allocator
|
||||
//from a range of iterators
|
||||
MyVector *myvector =
|
||||
MyVector *myvector =
|
||||
segment.construct<MyVector>
|
||||
("MyVector")/*object name*/
|
||||
(begVal /*first ctor parameter*/,
|
||||
endVal /*second ctor parameter*/,
|
||||
alloc_inst /*third ctor parameter*/);
|
||||
endVal /*second ctor parameter*/,
|
||||
alloc_inst /*third ctor parameter*/);
|
||||
|
||||
//Use vector as your want
|
||||
std::sort(myvector->rbegin(), myvector->rend());
|
||||
|
||||
@@ -44,15 +44,15 @@ int main(int argc, char *argv[])
|
||||
{ //Create a file
|
||||
file_mapping::remove(FileName);
|
||||
std::filebuf fbuf;
|
||||
fbuf.open(FileName, std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc | std::ios_base::binary);
|
||||
fbuf.open(FileName, std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc | std::ios_base::binary);
|
||||
//Set the size
|
||||
fbuf.pubseekoff(FileSize-1, std::ios_base::beg);
|
||||
fbuf.sputc(0);
|
||||
}
|
||||
|
||||
//Remove on exit
|
||||
struct file_remove
|
||||
struct file_remove
|
||||
{
|
||||
file_remove(const char *FileName)
|
||||
: FileName_(FileName) {}
|
||||
@@ -109,10 +109,10 @@ int main(int argc, char *argv[])
|
||||
std::filebuf fbuf;
|
||||
//<-
|
||||
#if 1
|
||||
fbuf.open(argv[2], std::ios_base::in | std::ios_base::binary);
|
||||
fbuf.open(argv[2], std::ios_base::in | std::ios_base::binary);
|
||||
#else
|
||||
//->
|
||||
fbuf.open(FileName, std::ios_base::in | std::ios_base::binary);
|
||||
fbuf.open(FileName, std::ios_base::in | std::ios_base::binary);
|
||||
//<-
|
||||
#endif
|
||||
//->
|
||||
|
||||
@@ -62,13 +62,13 @@ class reference_counted_class
|
||||
//A class that has an intrusive pointer to reference_counted_class
|
||||
class intrusive_ptr_owner
|
||||
{
|
||||
typedef intrusive_ptr<N::reference_counted_class,
|
||||
typedef intrusive_ptr<N::reference_counted_class,
|
||||
offset_ptr<void> > intrusive_ptr_t;
|
||||
intrusive_ptr_t m_intrusive_ptr;
|
||||
|
||||
public:
|
||||
//Takes a pointer to the reference counted class
|
||||
intrusive_ptr_owner(N::reference_counted_class *ptr)
|
||||
intrusive_ptr_owner(N::reference_counted_class *ptr)
|
||||
: m_intrusive_ptr(ptr){}
|
||||
};
|
||||
|
||||
@@ -105,12 +105,12 @@ int main()
|
||||
//->
|
||||
|
||||
//Create the unique reference counted object in shared memory
|
||||
N::reference_counted_class *ref_counted =
|
||||
N::reference_counted_class *ref_counted =
|
||||
shmem.construct<N::reference_counted_class>
|
||||
("ref_counted")(shmem.get_segment_manager());
|
||||
|
||||
//Create an array of ten intrusive pointer owners in shared memory
|
||||
intrusive_ptr_owner *intrusive_owner_array =
|
||||
intrusive_ptr_owner *intrusive_owner_array =
|
||||
shmem.construct<intrusive_ptr_owner>
|
||||
(anonymous_instance)[10](ref_counted);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ int main (int argc, char *argv[])
|
||||
using namespace boost::interprocess;
|
||||
if(argc == 1){ //Parent process
|
||||
//Remove shared memory on construction and destruction
|
||||
struct shm_remove
|
||||
struct shm_remove
|
||||
{
|
||||
//<-
|
||||
#if 1
|
||||
@@ -59,7 +59,7 @@ int main (int argc, char *argv[])
|
||||
if(free_memory <= segment.get_free_memory())
|
||||
return 1;
|
||||
|
||||
//An handle from the base address can identify any byte of the shared
|
||||
//An handle from the base address can identify any byte of the shared
|
||||
//memory segment even if it is mapped in different base addresses
|
||||
managed_shared_memory::handle_t handle = segment.get_handle_from_address(shptr);
|
||||
std::stringstream s;
|
||||
@@ -87,7 +87,7 @@ int main (int argc, char *argv[])
|
||||
#endif
|
||||
//->
|
||||
|
||||
//An handle from the base address can identify any byte of the shared
|
||||
//An handle from the base address can identify any byte of the shared
|
||||
//memory segment even if it is mapped in different base addresses
|
||||
managed_shared_memory::handle_t handle = 0;
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ int main()
|
||||
m_segment.deallocate(ptrs.back());
|
||||
ptrs.pop_back();
|
||||
ptrs.push_back(m_segment.allocate_aligned(128, 128));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -81,7 +81,7 @@ int main()
|
||||
{
|
||||
//Now create a read-only version
|
||||
managed_mapped_file managed_file_ro(open_read_only, ManagedFile);
|
||||
|
||||
|
||||
//Check the original is intact
|
||||
if(!managed_file_ro.find<int>("MyInt").first && managed_file_ro.find<int>("MyInt2").first)
|
||||
throw int(0);
|
||||
|
||||
@@ -54,9 +54,9 @@ int main()
|
||||
//from the first one and duplicate all the data.
|
||||
static boost::aligned_storage<memsize>::type static_buffer2;
|
||||
std::memcpy(&static_buffer2, &static_buffer, memsize);
|
||||
|
||||
|
||||
//Now open the duplicated managed memory passing the memory as argument
|
||||
wmanaged_external_buffer objects_in_static_memory2
|
||||
wmanaged_external_buffer objects_in_static_memory2
|
||||
(open_only, &static_buffer2, memsize);
|
||||
|
||||
//Check that "MyList" has been duplicated in the second buffer
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <cstddef>
|
||||
|
||||
using namespace boost::interprocess;
|
||||
typedef list<int, allocator<int, managed_heap_memory::segment_manager> >
|
||||
typedef list<int, allocator<int, managed_heap_memory::segment_manager> >
|
||||
MyList;
|
||||
|
||||
int main ()
|
||||
@@ -50,7 +50,7 @@ int main ()
|
||||
//use previously obtained handle to find the new pointer.
|
||||
mylist = static_cast<MyList *>
|
||||
(heap_memory.get_address_from_handle(list_handle));
|
||||
|
||||
|
||||
//Fill list until there is no more memory in the buffer
|
||||
try{
|
||||
while(1) {
|
||||
@@ -61,7 +61,7 @@ int main ()
|
||||
//memory is full
|
||||
}
|
||||
|
||||
//Let's obtain the new size of the list
|
||||
//Let's obtain the new size of the list
|
||||
MyList::size_type new_size = mylist->size();
|
||||
|
||||
assert(new_size > old_size);
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
//->
|
||||
|
||||
using namespace boost::interprocess;
|
||||
typedef list<int, allocator<int, managed_mapped_file::segment_manager> >
|
||||
typedef list<int, allocator<int, managed_mapped_file::segment_manager> >
|
||||
MyList;
|
||||
|
||||
int main ()
|
||||
{
|
||||
{
|
||||
//Define file names
|
||||
//<-
|
||||
#if 1
|
||||
@@ -77,7 +77,7 @@ int main ()
|
||||
//so use previously obtained handle to find the new pointer.
|
||||
MyList *mylist = static_cast<MyList *>
|
||||
(mfile_memory.get_address_from_handle(list_handle));
|
||||
|
||||
|
||||
//Fill list until there is no more room in the file
|
||||
try{
|
||||
while(1) {
|
||||
@@ -88,7 +88,7 @@ int main ()
|
||||
//mapped file is full
|
||||
}
|
||||
|
||||
//Let's obtain the new size of the list
|
||||
//Let's obtain the new size of the list
|
||||
MyList::size_type new_size = mylist->size();
|
||||
|
||||
assert(new_size > old_size);
|
||||
|
||||
@@ -51,7 +51,7 @@ int main ()
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment
|
||||
(create_only
|
||||
(create_only
|
||||
,"MySharedMemory" //segment name
|
||||
,65536); //segment size in bytes
|
||||
//<-
|
||||
@@ -67,7 +67,7 @@ int main ()
|
||||
//Alias an STL compatible allocator of for the map.
|
||||
//This allocator will allow to place containers
|
||||
//in managed shared memory segments
|
||||
typedef allocator<ValueType, managed_shared_memory::segment_manager>
|
||||
typedef allocator<ValueType, managed_shared_memory::segment_manager>
|
||||
ShmemAllocator;
|
||||
|
||||
//Alias a map of ints that uses the previous STL-like allocator.
|
||||
@@ -82,7 +82,7 @@ int main ()
|
||||
//Note that the first parameter is the comparison function,
|
||||
//and the second one the allocator.
|
||||
//This the same signature as std::map's constructor taking an allocator
|
||||
MyMap *mymap =
|
||||
MyMap *mymap =
|
||||
segment.construct<MyMap>("MyMap") //object name
|
||||
(std::less<int>() //first ctor parameter
|
||||
,alloc_inst); //second ctor parameter
|
||||
|
||||
@@ -28,7 +28,7 @@ int main ()
|
||||
typedef allocator<char, SegmentManager> CharAllocator;
|
||||
typedef basic_string<char, std::char_traits<char>
|
||||
,CharAllocator> MyShmString;
|
||||
typedef allocator<MyShmString, SegmentManager> StringAllocator;
|
||||
typedef allocator<MyShmString, SegmentManager> StringAllocator;
|
||||
typedef vector<MyShmString, StringAllocator> MyShmStringVector;
|
||||
|
||||
//Remove shared memory on construction and destruction
|
||||
@@ -38,7 +38,7 @@ int main ()
|
||||
#if 1
|
||||
shm_remove() { shared_memory_object::remove(test::get_process_id_name()); }
|
||||
~shm_remove(){ shared_memory_object::remove(test::get_process_id_name()); }
|
||||
#else
|
||||
#else
|
||||
//->
|
||||
shm_remove() { shared_memory_object::remove("MySharedMemory"); }
|
||||
~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
|
||||
@@ -65,7 +65,7 @@ int main ()
|
||||
StringAllocator stringallocator(shm.get_segment_manager());
|
||||
|
||||
//Create a vector of strings in shared memory.
|
||||
MyShmStringVector *myshmvector =
|
||||
MyShmStringVector *myshmvector =
|
||||
shm.construct<MyShmStringVector>("myshmvector")(stringallocator);
|
||||
|
||||
//Insert 50 strings in shared memory. The strings will be allocated
|
||||
@@ -73,7 +73,7 @@ int main ()
|
||||
//strings, leading to a great performance.
|
||||
MyShmString string_to_compare(charallocator);
|
||||
string_to_compare = "this is a long, long, long, long, long, long, string...";
|
||||
|
||||
|
||||
myshmvector->reserve(50);
|
||||
for(int i = 0; i < 50; ++i){
|
||||
MyShmString move_me(string_to_compare);
|
||||
@@ -94,7 +94,7 @@ int main ()
|
||||
|
||||
//...And insert one in the first position.
|
||||
//No string copy-constructor or assignments will be called, but
|
||||
//move constructors and move-assignments. No memory allocation
|
||||
//move constructors and move-assignments. No memory allocation
|
||||
//function will be called in this operations!!
|
||||
myshmvector->insert(myshmvector->begin(), boost::move(string_to_compare));
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if(argc == 1){ //Parent process
|
||||
//Remove shared memory on construction and destruction
|
||||
struct shm_remove
|
||||
struct shm_remove
|
||||
{
|
||||
//<-
|
||||
#if 1
|
||||
@@ -112,12 +112,12 @@ int main(int argc, char *argv[])
|
||||
std::pair<MyType*, managed_shared_memory::size_type> res;
|
||||
|
||||
//Find the array
|
||||
res = segment.find<MyType> ("MyType array");
|
||||
res = segment.find<MyType> ("MyType array");
|
||||
//Length should be 10
|
||||
if(res.second != 10) return 1;
|
||||
|
||||
//Find the object
|
||||
res = segment.find<MyType> ("MyType instance");
|
||||
res = segment.find<MyType> ("MyType instance");
|
||||
//Length should be 1
|
||||
if(res.second != 1) return 1;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int main ()
|
||||
//->
|
||||
|
||||
for(int i = 0; i < 10; ++i){
|
||||
|
||||
|
||||
//Do some operations...
|
||||
|
||||
//Write to file atomically
|
||||
|
||||
@@ -43,12 +43,12 @@ int main ()
|
||||
//Create shared memory
|
||||
//<-
|
||||
#if 1
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
test::get_process_id_name(), //segment name
|
||||
65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -49,12 +49,12 @@ int main ()
|
||||
//Create shared memory
|
||||
//<-
|
||||
#if 1
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
test::get_process_id_name(), //segment name
|
||||
65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
|
||||
@@ -43,12 +43,12 @@ int main ()
|
||||
//Create shared memory
|
||||
//<-
|
||||
#if 1
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
test::get_process_id_name(), //segment name
|
||||
65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
@@ -68,7 +68,7 @@ int main ()
|
||||
//is the same, this private_adaptive_pool will have its own pool so
|
||||
//"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance".
|
||||
//"allocator_instance2" is NOT equal to "allocator_instance"
|
||||
assert(allocator_instance != allocator_instance2);
|
||||
assert(allocator_instance != allocator_instance2);
|
||||
|
||||
//Create another adaptive_pool using copy-constructor.
|
||||
private_adaptive_pool_t allocator_instance3(allocator_instance2);
|
||||
|
||||
@@ -43,12 +43,12 @@ int main ()
|
||||
//Create shared memory
|
||||
//<-
|
||||
#if 1
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
test::get_process_id_name(), //segment name
|
||||
65536);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(create_only,
|
||||
managed_shared_memory segment(create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536);
|
||||
//<-
|
||||
@@ -68,7 +68,7 @@ int main ()
|
||||
//is the same, this private_node_allocator will have its own pool so
|
||||
//"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance".
|
||||
//"allocator_instance2" is NOT equal to "allocator_instance"
|
||||
assert(allocator_instance != allocator_instance2);
|
||||
assert(allocator_instance != allocator_instance2);
|
||||
|
||||
//Create another node_allocator using copy-constructor.
|
||||
private_node_allocator_t allocator_instance3(allocator_instance2);
|
||||
|
||||
@@ -86,7 +86,7 @@ int main ()
|
||||
my_class * my_object = shmem.construct<my_class>("my_object")();
|
||||
my_class * my_object2 = shmem.construct<my_class>(anonymous_instance)();
|
||||
shmem.destroy_ptr(my_object2);
|
||||
|
||||
|
||||
//Since the next shared memory allocation can throw
|
||||
//assign it to a scoped_ptr so that if an exception occurs
|
||||
//we destroy the object automatically
|
||||
|
||||
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if(argc == 1){ //Parent process
|
||||
//Remove shared memory on construction and destruction
|
||||
struct shm_remove
|
||||
struct shm_remove
|
||||
{
|
||||
//<-
|
||||
#if 1
|
||||
|
||||
@@ -62,7 +62,7 @@ int main ()
|
||||
//->
|
||||
|
||||
//Destroy any previous file with the name to be used.
|
||||
struct file_remove
|
||||
struct file_remove
|
||||
{
|
||||
file_remove(const char *MappedFile)
|
||||
: MappedFile_(MappedFile) { file_mapping::remove(MappedFile_); }
|
||||
@@ -128,11 +128,11 @@ int main ()
|
||||
//Now destroy the remaining owner. "object to share" will be destroyed
|
||||
file.destroy_ptr(owner2);
|
||||
assert(file.find<type_to_share>("object to share").first == 0);
|
||||
|
||||
|
||||
//Test observer
|
||||
assert(local_observer1.expired());
|
||||
assert(local_observer1.use_count() == 0);
|
||||
|
||||
|
||||
//The reference count will be deallocated when all weak pointers
|
||||
//disappear. After that, the file is unmapped.
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ int main ()
|
||||
//<-
|
||||
#endif
|
||||
//->
|
||||
|
||||
|
||||
//Create a shared pointer in shared memory
|
||||
//pointing to a newly created object in the segment
|
||||
my_shared_ptr &shared_ptr_instance =
|
||||
|
||||
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1){ //Parent process
|
||||
//Remove shared memory on construction and destruction
|
||||
struct shm_remove
|
||||
struct shm_remove
|
||||
{
|
||||
//<-
|
||||
#if 1
|
||||
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
|
||||
managed_shared_memory segment(open_only, argv[2]);
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(open_only, "MySharedMemory");
|
||||
managed_shared_memory segment(open_only, "MySharedMemory");
|
||||
//<-
|
||||
#endif
|
||||
//->
|
||||
|
||||
@@ -40,13 +40,13 @@ typedef managed_unique_ptr<MyType, managed_mapped_file>::type unique_ptr_type;
|
||||
//Define containers of unique pointer. Unique pointer simplifies object management
|
||||
typedef vector
|
||||
< unique_ptr_type
|
||||
, allocator<unique_ptr_type, managed_mapped_file::segment_manager>
|
||||
> unique_ptr_vector_t;
|
||||
, allocator<unique_ptr_type, managed_mapped_file::segment_manager>
|
||||
> unique_ptr_vector_t;
|
||||
|
||||
typedef list
|
||||
< unique_ptr_type
|
||||
, allocator<unique_ptr_type, managed_mapped_file::segment_manager>
|
||||
> unique_ptr_list_t;
|
||||
, allocator<unique_ptr_type, managed_mapped_file::segment_manager>
|
||||
> unique_ptr_list_t;
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -64,7 +64,7 @@ int main ()
|
||||
//->
|
||||
|
||||
//Destroy any previous file with the name to be used.
|
||||
struct file_remove
|
||||
struct file_remove
|
||||
{
|
||||
file_remove(const char *MappedFile)
|
||||
: MappedFile_(MappedFile) { file_mapping::remove(MappedFile_); }
|
||||
@@ -97,11 +97,11 @@ int main ()
|
||||
unique_vector->push_back(boost::move(p));
|
||||
assert(unique_vector->back()->number_ == i);
|
||||
}
|
||||
|
||||
|
||||
//Now create a list of unique pointers
|
||||
unique_ptr_list_t *unique_list =
|
||||
file.construct<unique_ptr_list_t>("unique list")(file.get_segment_manager());
|
||||
|
||||
|
||||
//Pass ownership of all values to the list
|
||||
for(int i = 99; !unique_vector->empty(); --i){
|
||||
unique_list->push_front(boost::move(unique_vector->back()));
|
||||
@@ -131,7 +131,7 @@ int main ()
|
||||
for(int i = 0; i < 100; ++i, ++list_it){
|
||||
assert((*list_it)->number_ == i);
|
||||
}
|
||||
|
||||
|
||||
//Now destroy the list. All elements will be automatically deallocated.
|
||||
file.destroy_ptr(unique_list);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
typedef allocator<int, managed_shared_memory::segment_manager>
|
||||
typedef allocator<int, managed_shared_memory::segment_manager>
|
||||
IntAllocator;
|
||||
typedef allocator<char, managed_shared_memory::segment_manager>
|
||||
typedef allocator<char, managed_shared_memory::segment_manager>
|
||||
CharAllocator;
|
||||
typedef vector<int, IntAllocator> MyVector;
|
||||
typedef basic_string
|
||||
@@ -55,13 +55,13 @@ int main ()
|
||||
//<-
|
||||
#if 1
|
||||
managed_shared_memory segment(
|
||||
create_only,
|
||||
create_only,
|
||||
test::get_process_id_name(), //segment name
|
||||
65536); //segment size in bytes
|
||||
#else
|
||||
//->
|
||||
managed_shared_memory segment(
|
||||
create_only,
|
||||
create_only,
|
||||
"MySharedMemory", //segment name
|
||||
65536); //segment size in bytes
|
||||
//<-
|
||||
@@ -69,7 +69,7 @@ int main ()
|
||||
//->
|
||||
|
||||
//Construct shared memory vector
|
||||
MyVector *myvector =
|
||||
MyVector *myvector =
|
||||
segment.construct<MyVector>("MyVector")
|
||||
(IntAllocator(segment.get_segment_manager()));
|
||||
|
||||
@@ -102,7 +102,7 @@ int main ()
|
||||
//Avoid reallocations
|
||||
myvector2->reserve(100);
|
||||
|
||||
//Extract all values from the internal
|
||||
//Extract all values from the internal
|
||||
//string directly to a shared memory vector.
|
||||
std::istream_iterator<int> it(myvectorstream), itend;
|
||||
std::copy(it, itend, std::back_inserter(*myvector2));
|
||||
@@ -114,7 +114,7 @@ int main ()
|
||||
MyString stringcopy (myvectorstream.vector());
|
||||
|
||||
//Now we create a new empty shared memory string...
|
||||
MyString *mystring =
|
||||
MyString *mystring =
|
||||
segment.construct<MyString>("MyString")
|
||||
(CharAllocator(segment.get_segment_manager()));
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ int main ()
|
||||
{
|
||||
using namespace boost::interprocess;
|
||||
//Typedefs
|
||||
typedef allocator<char, managed_shared_memory::segment_manager>
|
||||
typedef allocator<char, managed_shared_memory::segment_manager>
|
||||
CharAllocator;
|
||||
typedef basic_string<char, std::char_traits<char>, CharAllocator>
|
||||
MyShmString;
|
||||
typedef allocator<MyShmString, managed_shared_memory::segment_manager>
|
||||
StringAllocator;
|
||||
StringAllocator;
|
||||
typedef vector<MyShmString, StringAllocator>
|
||||
MyShmStringVector;
|
||||
|
||||
@@ -66,17 +66,17 @@ int main ()
|
||||
StringAllocator stringallocator(shm.get_segment_manager());
|
||||
|
||||
//This string is in only in this process (the pointer pointing to the
|
||||
//buffer that will hold the text is not in shared memory).
|
||||
//But the buffer that will hold "this is my text" is allocated from
|
||||
//buffer that will hold the text is not in shared memory).
|
||||
//But the buffer that will hold "this is my text" is allocated from
|
||||
//shared memory
|
||||
MyShmString mystring(charallocator);
|
||||
mystring = "this is my text";
|
||||
|
||||
//This vector is only in this process (the pointer pointing to the
|
||||
//buffer that will hold the MyShmString-s is not in shared memory).
|
||||
//But the buffer that will hold 10 MyShmString-s is allocated from
|
||||
//shared memory using StringAllocator. Since strings use a shared
|
||||
//memory allocator (CharAllocator) the 10 buffers that hold
|
||||
//buffer that will hold the MyShmString-s is not in shared memory).
|
||||
//But the buffer that will hold 10 MyShmString-s is allocated from
|
||||
//shared memory using StringAllocator. Since strings use a shared
|
||||
//memory allocator (CharAllocator) the 10 buffers that hold
|
||||
//"this is my text" text are also in shared memory.
|
||||
MyShmStringVector myvector(stringallocator);
|
||||
myvector.insert(myvector.begin(), 10, mystring);
|
||||
@@ -84,7 +84,7 @@ int main ()
|
||||
//This vector is fully constructed in shared memory. All pointers
|
||||
//buffers are constructed in the same shared memory segment
|
||||
//This vector can be safely accessed from other processes.
|
||||
MyShmStringVector *myshmvector =
|
||||
MyShmStringVector *myshmvector =
|
||||
shm.construct<MyShmStringVector>("myshmvector")(stringallocator);
|
||||
myshmvector->insert(myshmvector->begin(), 10, mystring);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
|
||||
xsi_shared_memory shm (create_only, key, 1000);
|
||||
|
||||
//Remove shared memory on destruction
|
||||
struct shm_remove
|
||||
struct shm_remove
|
||||
{
|
||||
int shmid_;
|
||||
shm_remove(int shmid) : shmid_(shmid){}
|
||||
|
||||
@@ -120,7 +120,7 @@ All Fine
|
||||
-> map::node_ptr p = m.create_node(my_special_cheap_key_value, mv1, mv2);
|
||||
//We would need to unconst-cast...
|
||||
const_cast<Key&>(p->first) = modify( p->second );
|
||||
m.insert( boost::move(p) );
|
||||
m.insert( boost::move(p) );
|
||||
|
||||
-> I found some bug in the interprocess library. I use
|
||||
boost::interprocess::managed_mapped_file class and
|
||||
@@ -164,7 +164,7 @@ LOCK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
UNLOCK
|
||||
if (fixing_mode){
|
||||
|
||||
@@ -315,7 +315,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "semaphore_test", "semaphore
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared_memory_mapping_test", "shared_memory_mappable_test.vcproj", "{5CE18C83-6025-36FE-A4F7-BA09176D3A11}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared_memory_mapping_test", "shared_memory_mapping_test.vcproj", "{5CE18C83-6025-36FE-A4F7-BA09176D3A11}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/mapped_file_test_d.exe"
|
||||
OutputFile="$(OutDir)/anonymous_shared_memory_test_d.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/mapped_file_test_d.exe"
|
||||
OutputFile="$(OutDir)/file_mapping_test_d.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="../../Bin/Win32/Debug"
|
||||
IntermediateDirectory="Debug/shared_memory_mappable_test"
|
||||
IntermediateDirectory="Debug/shared_memory_mapping_test"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
@@ -38,11 +38,11 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/mapped_file_test_d.exe"
|
||||
OutputFile="$(OutDir)/shared_memory_mapping_test_d.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/shared_memory_mappable_test.pdb"
|
||||
ProgramDatabaseFile="$(OutDir)/shared_memory_mapping_test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
FixedBaseAddress="1"/>
|
||||
@@ -70,7 +70,7 @@
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="../../Bin/Win32/Release"
|
||||
IntermediateDirectory="Release/shared_memory_mappable_test"
|
||||
IntermediateDirectory="Release/shared_memory_mapping_test"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
@@ -90,7 +90,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/shared_memory_mappable_test.exe"
|
||||
OutputFile="$(OutDir)/shared_memory_mapping_test.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
@@ -35,7 +35,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/mapped_file_test_d.exe"
|
||||
OutputFile="$(OutDir)/windows_shared_memory_mapping_test.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/mapped_file_test_d.exe"
|
||||
OutputFile="$(OutDir)/xsi_shared_memory_mapping_test_d.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# Boost Interprocess Library Test Jamfile
|
||||
|
||||
# (C) Copyright Ion Gaztanaga 2006.
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Adapted from John Maddock's TR1 Jamfile.v2
|
||||
# Copyright John Maddock 2005.
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# this rule enumerates through all the sources and invokes
|
||||
@@ -27,7 +27,7 @@ rule test_all
|
||||
: # requirements
|
||||
<toolset>acc:<linkflags>-lrt
|
||||
<toolset>acc-pa_risc:<linkflags>-lrt
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<toolset>gcc-mingw:<linkflags>"-lole32 -loleaut32 -lpsapi -ladvapi32"
|
||||
<host-os>hpux,<toolset>gcc:<linkflags>"-Wl,+as,mpas"
|
||||
] ;
|
||||
}
|
||||
@@ -35,4 +35,4 @@ rule test_all
|
||||
return $(all_rules) ;
|
||||
}
|
||||
|
||||
test-suite interprocess_test : [ test_all r ] : <threading>multi ;
|
||||
test-suite interprocess_test : [ test_all r ] : <threading>multi ;
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace boost {
|
||||
namespace interprocess {
|
||||
namespace test {
|
||||
|
||||
//!An STL compatible allocator_v1 that uses a segment manager as
|
||||
//!An STL compatible allocator_v1 that uses a segment manager as
|
||||
//!memory source. The internal pointer type will of the same type (raw, smart) as
|
||||
//!"typename SegmentManager::void_pointer" type. This allows
|
||||
//!placing the allocator_v1 in shared memory, memory mapped-files, etc...*/
|
||||
template<class T, class SegmentManager>
|
||||
class allocator_v1
|
||||
class allocator_v1
|
||||
{
|
||||
private:
|
||||
typedef allocator_v1<T, SegmentManager> self_t;
|
||||
@@ -86,7 +86,7 @@ class allocator_v1
|
||||
//!Obtains an allocator_v1 of other type
|
||||
template<class T2>
|
||||
struct rebind
|
||||
{
|
||||
{
|
||||
typedef allocator_v1<T2, SegmentManager> other;
|
||||
};
|
||||
|
||||
@@ -103,19 +103,19 @@ class allocator_v1
|
||||
{ return const_pointer(addressof(value)); }
|
||||
*/
|
||||
//!Constructor from the segment manager. Never throws
|
||||
allocator_v1(segment_manager *segment_mngr)
|
||||
allocator_v1(segment_manager *segment_mngr)
|
||||
: mp_mngr(segment_mngr) { }
|
||||
|
||||
//!Constructor from other allocator_v1. Never throws
|
||||
allocator_v1(const allocator_v1 &other)
|
||||
allocator_v1(const allocator_v1 &other)
|
||||
: mp_mngr(other.get_segment_manager()){ }
|
||||
|
||||
//!Constructor from related allocator_v1. Never throws
|
||||
template<class T2>
|
||||
allocator_v1(const allocator_v1<T2, SegmentManager> &other)
|
||||
allocator_v1(const allocator_v1<T2, SegmentManager> &other)
|
||||
: mp_mngr(other.get_segment_manager()){}
|
||||
|
||||
//!Allocates memory for an array of count elements.
|
||||
//!Allocates memory for an array of count elements.
|
||||
//!Throws boost::interprocess::bad_alloc if there is no enough memory
|
||||
pointer allocate(size_type count, cvoid_ptr hint = 0)
|
||||
{ (void)hint; return pointer(static_cast<value_type*>(mp_mngr->allocate(count*sizeof(value_type)))); }
|
||||
@@ -124,7 +124,7 @@ class allocator_v1
|
||||
void deallocate(const pointer &ptr, size_type)
|
||||
{ mp_mngr->deallocate((void*)ipcdetail::to_raw_pointer(ptr)); }
|
||||
|
||||
//!Construct object, calling constructor.
|
||||
//!Construct object, calling constructor.
|
||||
//!Throws if T(const T&) throws
|
||||
void construct(const pointer &ptr, const_reference value)
|
||||
{ new((void*)ipcdetail::to_raw_pointer(ptr)) value_type(value); }
|
||||
@@ -145,13 +145,13 @@ class allocator_v1
|
||||
|
||||
//!Equality test for same type of allocator_v1
|
||||
template<class T, class SegmentManager> inline
|
||||
bool operator==(const allocator_v1<T , SegmentManager> &alloc1,
|
||||
bool operator==(const allocator_v1<T , SegmentManager> &alloc1,
|
||||
const allocator_v1<T, SegmentManager> &alloc2)
|
||||
{ return alloc1.get_segment_manager() == alloc2.get_segment_manager(); }
|
||||
|
||||
//!Inequality test for same type of allocator_v1
|
||||
template<class T, class SegmentManager> inline
|
||||
bool operator!=(const allocator_v1<T, SegmentManager> &alloc1,
|
||||
bool operator!=(const allocator_v1<T, SegmentManager> &alloc1,
|
||||
const allocator_v1<T, SegmentManager> &alloc2)
|
||||
{ return alloc1.get_segment_manager() != alloc2.get_segment_manager(); }
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ int main ()
|
||||
managed_shared_memory segment(create_only, shMemName, memsize);
|
||||
|
||||
//STL compatible allocator object, uses allocate(), deallocate() functions
|
||||
typedef allocator<InstanceCounter,
|
||||
typedef allocator<InstanceCounter,
|
||||
managed_shared_memory::segment_manager>
|
||||
inst_allocator_t;
|
||||
const inst_allocator_t myallocator (segment.get_segment_manager());
|
||||
@@ -59,7 +59,7 @@ int main ()
|
||||
int i;
|
||||
for(i = 0; true; ++i){
|
||||
myvec.push_back(InstanceCounter());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(boost::interprocess::bad_alloc &){
|
||||
if(InstanceCounter::counter != 0)
|
||||
@@ -74,7 +74,7 @@ int main ()
|
||||
InstanceCounter ic;
|
||||
for(i = 0; true; ++i){
|
||||
myvec.insert(myvec.begin(), i, ic);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(boost::interprocess::bad_alloc &){
|
||||
if(InstanceCounter::counter != 0)
|
||||
|
||||
@@ -60,10 +60,10 @@ static int bufferstream_test()
|
||||
bufstream >> str1 >> number1;
|
||||
std_stringstream >> str2 >> number2;
|
||||
if((str1 != str2) || (str1 != str3)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
if((number1 != number2) || (number1 != i)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
}
|
||||
//We shouldn't have reached the end of the buffer reading
|
||||
@@ -90,7 +90,7 @@ static int bufferstream_test()
|
||||
bufstream << "testline: " << i << std::endl;
|
||||
std_stringstream << "testline: " << i << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//Contents should be different
|
||||
if(std::strcmp(buffer, std_stringstream.str().c_str()) == 0){
|
||||
return 1;
|
||||
@@ -117,7 +117,7 @@ static int bufferstream_test()
|
||||
assert(0);
|
||||
return 1;
|
||||
}
|
||||
//The eof flag indicates we have reached the end of the
|
||||
//The eof flag indicates we have reached the end of the
|
||||
//buffer while reading
|
||||
if(!bufstream.eof()){
|
||||
assert(0);
|
||||
|
||||
@@ -33,7 +33,7 @@ bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont)
|
||||
typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
|
||||
typename MyStdCont::iterator itstd(stdcont->begin());
|
||||
typename MyStdCont::size_type dist = (typename MyStdCont::size_type)std::distance(itshm, itshmend);
|
||||
if(dist != shmcont->size()){
|
||||
if(dist != shmcont->size()){
|
||||
return false;
|
||||
}
|
||||
std::size_t i = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace test {
|
||||
|
||||
boost::posix_time::ptime ptime_delay(int secs)
|
||||
{
|
||||
return microsec_clock::universal_time() +
|
||||
return microsec_clock::universal_time() +
|
||||
boost::posix_time::time_duration(0, 0, secs);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ struct condition_test_data
|
||||
template <class Condition, class Mutex>
|
||||
void condition_test_thread(condition_test_data<Condition, Mutex>* data)
|
||||
{
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
lock(data->mutex);
|
||||
BOOST_INTERPROCES_CHECK(lock ? true : false);
|
||||
while (!(data->notified > 0))
|
||||
@@ -117,7 +117,7 @@ struct cond_predicate
|
||||
template <class Condition, class Mutex>
|
||||
void condition_test_waits(condition_test_data<Condition, Mutex>* data)
|
||||
{
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
lock(data->mutex);
|
||||
BOOST_INTERPROCES_CHECK(lock ? true : false);
|
||||
|
||||
@@ -162,7 +162,7 @@ void do_test_condition_notify_one()
|
||||
|
||||
boost::thread thread(bind_function(&condition_test_thread<Condition, Mutex>, &data));
|
||||
{
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
lock(data.mutex);
|
||||
BOOST_INTERPROCES_CHECK(lock ? true : false);
|
||||
data.notified++;
|
||||
@@ -184,7 +184,7 @@ void do_test_condition_notify_all()
|
||||
threads.create_thread(bind_function(&condition_test_thread<Condition, Mutex>, &data));
|
||||
|
||||
{
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
boost::interprocess::scoped_lock<Mutex>
|
||||
lock(data.mutex);
|
||||
BOOST_INTERPROCES_CHECK(lock ? true : false);
|
||||
data.notified++;
|
||||
|
||||
@@ -52,7 +52,7 @@ int main ()
|
||||
//---- ALLOC, NAMED_ALLOC, NAMED_NEW TEST ----//
|
||||
{
|
||||
int i;
|
||||
//Let's allocate some memory
|
||||
//Let's allocate some memory
|
||||
for(i = 0; i < max; ++i){
|
||||
array[i] = segment.allocate(i+1);
|
||||
}
|
||||
|
||||
@@ -261,11 +261,11 @@ bool do_test()
|
||||
|
||||
shmdeque->resize(100);
|
||||
stddeque->resize(100);
|
||||
if(!test::CheckEqualContainers(shmdeque, stddeque)) return 1;
|
||||
if(!test::CheckEqualContainers(shmdeque, stddeque)) return 1;
|
||||
|
||||
shmdeque->resize(200);
|
||||
stddeque->resize(200);
|
||||
if(!test::CheckEqualContainers(shmdeque, stddeque)) return 1;
|
||||
if(!test::CheckEqualContainers(shmdeque, stddeque)) return 1;
|
||||
|
||||
segment.template destroy<MyShmDeque>("MyShmDeque");
|
||||
delete stddeque;
|
||||
@@ -278,7 +278,7 @@ bool do_test()
|
||||
std::cout << ex.what() << std::endl;
|
||||
return false;
|
||||
}*/
|
||||
|
||||
|
||||
std::cout << std::endl << "Test OK!" << std::endl;
|
||||
}/*
|
||||
catch(...){
|
||||
|
||||
@@ -37,11 +37,11 @@ namespace boost {
|
||||
namespace interprocess {
|
||||
namespace test {
|
||||
|
||||
//This allocator just allows two allocations. The first one will return
|
||||
//This allocator just allows two allocations. The first one will return
|
||||
//mp_buffer + m_offset configured in the constructor. The second one
|
||||
//will return mp_buffer.
|
||||
template<class T>
|
||||
class dummy_test_allocator
|
||||
class dummy_test_allocator
|
||||
{
|
||||
private:
|
||||
typedef dummy_test_allocator<T> self_t;
|
||||
@@ -72,7 +72,7 @@ class dummy_test_allocator
|
||||
|
||||
//!Default constructor. Never throws
|
||||
dummy_test_allocator()
|
||||
{}
|
||||
{}
|
||||
|
||||
//!Constructor from other dummy_test_allocator. Never throws
|
||||
dummy_test_allocator(const dummy_test_allocator &)
|
||||
@@ -83,7 +83,7 @@ class dummy_test_allocator
|
||||
dummy_test_allocator(const dummy_test_allocator<T2> &)
|
||||
{}
|
||||
|
||||
pointer address(reference value)
|
||||
pointer address(reference value)
|
||||
{ return pointer(addressof(value)); }
|
||||
|
||||
const_pointer address(const_reference value) const
|
||||
@@ -112,7 +112,7 @@ class dummy_test_allocator
|
||||
|
||||
std::pair<pointer, bool>
|
||||
allocation_command(boost::interprocess::allocation_type,
|
||||
size_type,
|
||||
size_type,
|
||||
size_type,
|
||||
size_type &, const pointer & = 0)
|
||||
{ return std::pair<pointer, bool>(pointer(0), true); }
|
||||
@@ -137,13 +137,13 @@ class dummy_test_allocator
|
||||
|
||||
//!Equality test for same type of dummy_test_allocator
|
||||
template<class T> inline
|
||||
bool operator==(const dummy_test_allocator<T> &,
|
||||
bool operator==(const dummy_test_allocator<T> &,
|
||||
const dummy_test_allocator<T> &)
|
||||
{ return false; }
|
||||
|
||||
//!Inequality test for same type of dummy_test_allocator
|
||||
template<class T> inline
|
||||
bool operator!=(const dummy_test_allocator<T> &,
|
||||
bool operator!=(const dummy_test_allocator<T> &,
|
||||
const dummy_test_allocator<T> &)
|
||||
{ return true; }
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ namespace boost {
|
||||
namespace interprocess {
|
||||
namespace test {
|
||||
|
||||
//This allocator just allows two allocations. The first one will return
|
||||
//This allocator just allows two allocations. The first one will return
|
||||
//mp_buffer + m_offset configured in the constructor. The second one
|
||||
//will return mp_buffer.
|
||||
template<class T>
|
||||
class expand_bwd_test_allocator
|
||||
class expand_bwd_test_allocator
|
||||
{
|
||||
private:
|
||||
typedef expand_bwd_test_allocator<T> self_t;
|
||||
@@ -71,12 +71,12 @@ class expand_bwd_test_allocator
|
||||
{ typedef expand_bwd_test_allocator<T2> other; };
|
||||
|
||||
//!Constructor from the segment manager. Never throws
|
||||
expand_bwd_test_allocator(T *buffer, size_type size, difference_type offset)
|
||||
expand_bwd_test_allocator(T *buffer, size_type size, difference_type offset)
|
||||
: mp_buffer(buffer), m_size(size)
|
||||
, m_offset(offset), m_allocations(0){ }
|
||||
|
||||
//!Constructor from other expand_bwd_test_allocator. Never throws
|
||||
expand_bwd_test_allocator(const expand_bwd_test_allocator &other)
|
||||
expand_bwd_test_allocator(const expand_bwd_test_allocator &other)
|
||||
: mp_buffer(other.mp_buffer), m_size(other.m_size)
|
||||
, m_offset(other.m_offset), m_allocations(0){ }
|
||||
|
||||
@@ -109,7 +109,7 @@ class expand_bwd_test_allocator
|
||||
{ return m_size; }
|
||||
|
||||
friend void swap(self_t &alloc1, self_t &alloc2)
|
||||
{
|
||||
{
|
||||
ipcdetail::do_swap(alloc1.mp_buffer, alloc2.mp_buffer);
|
||||
ipcdetail::do_swap(alloc1.m_size, alloc2.m_size);
|
||||
ipcdetail::do_swap(alloc1.m_offset, alloc2.m_offset);
|
||||
@@ -119,14 +119,14 @@ class expand_bwd_test_allocator
|
||||
|
||||
std::pair<pointer, bool>
|
||||
allocation_command(boost::interprocess::allocation_type command,
|
||||
size_type limit_size,
|
||||
size_type limit_size,
|
||||
size_type preferred_size,
|
||||
size_type &received_size, const pointer &reuse = 0)
|
||||
{
|
||||
(void)preferred_size; (void)reuse; (void)command;
|
||||
//This allocator only expands backwards!
|
||||
assert(m_allocations == 0 || (command & boost::interprocess::expand_bwd));
|
||||
|
||||
|
||||
received_size = limit_size;
|
||||
|
||||
if(m_allocations == 0){
|
||||
@@ -174,13 +174,13 @@ class expand_bwd_test_allocator
|
||||
|
||||
//!Equality test for same type of expand_bwd_test_allocator
|
||||
template<class T> inline
|
||||
bool operator==(const expand_bwd_test_allocator<T> &alloc1,
|
||||
bool operator==(const expand_bwd_test_allocator<T> &alloc1,
|
||||
const expand_bwd_test_allocator<T> &alloc2)
|
||||
{ return false; }
|
||||
|
||||
//!Inequality test for same type of expand_bwd_test_allocator
|
||||
template<class T> inline
|
||||
bool operator!=(const expand_bwd_test_allocator<T> &alloc1,
|
||||
bool operator!=(const expand_bwd_test_allocator<T> &alloc1,
|
||||
const expand_bwd_test_allocator<T> &alloc2)
|
||||
{ return true; }
|
||||
|
||||
|
||||
@@ -113,19 +113,19 @@ bool test_insert_with_expand_bwd()
|
||||
const int MemorySize = 1000;
|
||||
|
||||
//Distance old and new buffer
|
||||
const int Offset[] =
|
||||
const int Offset[] =
|
||||
{ 350, 250, 150, 150,
|
||||
150, 50, 50, 50 };
|
||||
//Insert position
|
||||
const int Position[] =
|
||||
const int Position[] =
|
||||
{ 100, 100, 100, 100,
|
||||
100, 100, 100, 100 };
|
||||
//Initial vector size
|
||||
const int InitialSize[] =
|
||||
const int InitialSize[] =
|
||||
{ 200, 200, 200, 200,
|
||||
200, 200, 200, 200 };
|
||||
//Size of the data to insert
|
||||
const int InsertSize[] =
|
||||
const int InsertSize[] =
|
||||
{ 100, 100, 100, 200,
|
||||
300, 25, 100, 200 };
|
||||
//Number of tests
|
||||
@@ -158,7 +158,7 @@ bool test_insert_with_expand_bwd()
|
||||
, data_to_insert.begin(), data_to_insert.end());
|
||||
//Now check that values are equal
|
||||
if(!CheckEqualVector(vector, initial_data)){
|
||||
std::cout << "test_assign_with_expand_bwd::CheckEqualVector failed." << std::endl
|
||||
std::cout << "test_assign_with_expand_bwd::CheckEqualVector failed." << std::endl
|
||||
<< " Class: " << typeid(VectorWithExpandBwdAllocator).name() << std::endl
|
||||
<< " Iteration: " << iteration << std::endl;
|
||||
return false;
|
||||
@@ -214,13 +214,13 @@ bool test_assign_with_expand_bwd()
|
||||
vector.insert( vector.begin()
|
||||
, initial_data.begin(), initial_data.end());
|
||||
|
||||
//Assign data
|
||||
//Assign data
|
||||
vector.assign(data_to_assign.begin(), data_to_assign.end());
|
||||
initial_data.assign(data_to_assign.begin(), data_to_assign.end());
|
||||
|
||||
//Now check that values are equal
|
||||
if(!CheckEqualVector(vector, initial_data)){
|
||||
std::cout << "test_assign_with_expand_bwd::CheckEqualVector failed." << std::endl
|
||||
std::cout << "test_assign_with_expand_bwd::CheckEqualVector failed." << std::endl
|
||||
<< " Class: " << typeid(VectorWithExpandBwdAllocator).name() << std::endl
|
||||
<< " Iteration: " << iteration << std::endl;
|
||||
return false;
|
||||
|
||||
@@ -62,7 +62,7 @@ int main ()
|
||||
,FileSize - FileSize/2
|
||||
);
|
||||
|
||||
//Fill two regions with a pattern
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
@@ -85,7 +85,7 @@ int main ()
|
||||
|
||||
//Create a memory buffer
|
||||
std::auto_ptr<unsigned char> memory (new unsigned char [FileSize/2 +1]);
|
||||
|
||||
|
||||
//Fill buffer
|
||||
file.read(static_cast<char*>(static_cast<void*>(memory.get()))
|
||||
, FileSize/2);
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
#include "emplace_test.hpp"
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This example repeats the same operations with std::set and
|
||||
// shmem_set using the node allocator
|
||||
// and compares the values of both containers
|
||||
//
|
||||
//
|
||||
// This example repeats the same operations with std::set and
|
||||
// shmem_set using the node allocator
|
||||
// and compares the values of both containers
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace boost::interprocess;
|
||||
@@ -41,22 +41,22 @@ typedef basic_managed_shared_memory
|
||||
> my_managed_shared_memory;
|
||||
|
||||
//Alias allocator type
|
||||
typedef allocator<int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<int, my_managed_shared_memory::segment_manager>
|
||||
shmem_allocator_t;
|
||||
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_movable_allocator_t;
|
||||
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_pair_allocator_t;
|
||||
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_movable_pair_allocator_t;
|
||||
|
||||
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_move_copy_allocator_t;
|
||||
|
||||
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_copy_allocator_t;
|
||||
|
||||
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_move_copy_pair_allocator_t;
|
||||
|
||||
//Alias set types
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace boost {
|
||||
namespace interprocess {
|
||||
namespace test {
|
||||
|
||||
//!An STL compatible heap_allocator_v1 that uses a segment manager as
|
||||
//!An STL compatible heap_allocator_v1 that uses a segment manager as
|
||||
//!memory source. The internal pointer type will of the same type (raw, smart) as
|
||||
//!"typename SegmentManager::void_pointer" type. This allows
|
||||
//!placing the heap_allocator_v1 in shared memory, memory mapped-files, etc...*/
|
||||
template<class T, class SegmentManager>
|
||||
class heap_allocator_v1
|
||||
class heap_allocator_v1
|
||||
{
|
||||
private:
|
||||
typedef heap_allocator_v1<T, SegmentManager> self_t;
|
||||
@@ -83,7 +83,7 @@ class heap_allocator_v1
|
||||
//!Obtains an heap_allocator_v1 of other type
|
||||
template<class T2>
|
||||
struct rebind
|
||||
{
|
||||
{
|
||||
typedef heap_allocator_v1<T2, SegmentManager> other;
|
||||
};
|
||||
|
||||
@@ -100,19 +100,19 @@ class heap_allocator_v1
|
||||
{ return const_pointer(addressof(value)); }
|
||||
|
||||
//!Constructor from the segment manager. Never throws
|
||||
heap_allocator_v1(segment_manager *segment_mngr)
|
||||
heap_allocator_v1(segment_manager *segment_mngr)
|
||||
: mp_mngr(segment_mngr) { }
|
||||
|
||||
//!Constructor from other heap_allocator_v1. Never throws
|
||||
heap_allocator_v1(const heap_allocator_v1 &other)
|
||||
heap_allocator_v1(const heap_allocator_v1 &other)
|
||||
: mp_mngr(other.get_segment_manager()){ }
|
||||
|
||||
//!Constructor from related heap_allocator_v1. Never throws
|
||||
template<class T2>
|
||||
heap_allocator_v1(const heap_allocator_v1<T2, SegmentManager> &other)
|
||||
heap_allocator_v1(const heap_allocator_v1<T2, SegmentManager> &other)
|
||||
: mp_mngr(other.get_segment_manager()){}
|
||||
|
||||
//!Allocates memory for an array of count elements.
|
||||
//!Allocates memory for an array of count elements.
|
||||
//!Throws boost::interprocess::bad_alloc if there is no enough memory
|
||||
pointer allocate(size_type count, cvoid_ptr hint = 0)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ class heap_allocator_v1
|
||||
void deallocate(const pointer &ptr, size_type)
|
||||
{ return ::delete[] ipcdetail::to_raw_pointer(ptr) ; }
|
||||
|
||||
//!Construct object, calling constructor.
|
||||
//!Construct object, calling constructor.
|
||||
//!Throws if T(const T&) throws
|
||||
void construct(const pointer &ptr, const_reference value)
|
||||
{ new((void*)ipcdetail::to_raw_pointer(ptr)) value_type(value); }
|
||||
@@ -146,13 +146,13 @@ class heap_allocator_v1
|
||||
|
||||
//!Equality test for same type of heap_allocator_v1
|
||||
template<class T, class SegmentManager> inline
|
||||
bool operator==(const heap_allocator_v1<T , SegmentManager> &alloc1,
|
||||
bool operator==(const heap_allocator_v1<T , SegmentManager> &alloc1,
|
||||
const heap_allocator_v1<T, SegmentManager> &alloc2)
|
||||
{ return alloc1.get_segment_manager() == alloc2.get_segment_manager(); }
|
||||
|
||||
//!Inequality test for same type of heap_allocator_v1
|
||||
template<class T, class SegmentManager> inline
|
||||
bool operator!=(const heap_allocator_v1<T, SegmentManager> &alloc1,
|
||||
bool operator!=(const heap_allocator_v1<T, SegmentManager> &alloc1,
|
||||
const heap_allocator_v1<T, SegmentManager> &alloc2)
|
||||
{ return alloc1.get_segment_manager() != alloc2.get_segment_manager(); }
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class MyThrowingClass
|
||||
};
|
||||
|
||||
|
||||
template < template<class, bool = false> class IntermoduleType >
|
||||
template < template<class T, bool LazyInit = false, bool Phoenix = true> class IntermoduleType >
|
||||
int intermodule_singleton_test()
|
||||
{
|
||||
bool exception_thrown = false;
|
||||
@@ -87,7 +87,171 @@ int intermodule_singleton_test()
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//A class simulating a logger
|
||||
//We'll register constructor/destructor counts
|
||||
//to test the singleton was correctly resurrected
|
||||
//by LogUser singleton.
|
||||
template<class Tag>
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger()
|
||||
{
|
||||
++constructed_times;
|
||||
}
|
||||
|
||||
void log_it()
|
||||
{}
|
||||
|
||||
~Logger()
|
||||
{
|
||||
++destroyed_times;
|
||||
}
|
||||
|
||||
static unsigned int constructed_times;
|
||||
static unsigned int destroyed_times;
|
||||
};
|
||||
|
||||
template<class Tag>
|
||||
unsigned int Logger<Tag>::constructed_times;
|
||||
|
||||
template<class Tag>
|
||||
unsigned int Logger<Tag>::destroyed_times;
|
||||
|
||||
//A class simulating a logger user.
|
||||
//The destructor uses the logger so that
|
||||
//the logger is resurrected if it was
|
||||
//already destroyed
|
||||
template<class LogSingleton>
|
||||
class LogUser
|
||||
{
|
||||
public:
|
||||
LogUser()
|
||||
{}
|
||||
|
||||
void function_using_log()
|
||||
{ LogSingleton::get().log_it(); }
|
||||
|
||||
~LogUser()
|
||||
{ LogSingleton::get().log_it(); }
|
||||
};
|
||||
|
||||
//A class that tests the correct
|
||||
//phoenix singleton behaviour.
|
||||
//Logger should be resurrected by LogUser
|
||||
template<class Tag>
|
||||
class LogPhoenixTester
|
||||
{
|
||||
public:
|
||||
LogPhoenixTester()
|
||||
{}
|
||||
|
||||
void dummy()
|
||||
{}
|
||||
|
||||
~LogPhoenixTester()
|
||||
{
|
||||
//Test Phoenix singleton was correctly executed:
|
||||
//created and destroyed two times
|
||||
//This test will be executed after main ends
|
||||
if(Logger<Tag>::constructed_times != Logger<Tag>::destroyed_times ||
|
||||
Logger<Tag>::constructed_times != 2)
|
||||
{
|
||||
std::string s("LogPhoenixTester failed for tag ");
|
||||
s += typeid(Tag).name();
|
||||
throw std::runtime_error(s.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//A class simulating a logger user.
|
||||
//The destructor uses the logger so that
|
||||
//the logger is resurrected if it was
|
||||
//already destroyed
|
||||
template<class LogSingleton>
|
||||
class LogDeadReferenceUser
|
||||
{
|
||||
public:
|
||||
LogDeadReferenceUser()
|
||||
{}
|
||||
|
||||
void function_using_log()
|
||||
{ LogSingleton::get().log_it(); }
|
||||
|
||||
~LogDeadReferenceUser()
|
||||
{
|
||||
//Make sure the exception is thrown as we are
|
||||
//try to use a dead non-phoenix singleton
|
||||
try{
|
||||
LogSingleton::get().log_it();
|
||||
std::string s("LogDeadReferenceUser failed for LogSingleton ");
|
||||
s += typeid(LogSingleton).name();
|
||||
throw std::runtime_error(s.c_str());
|
||||
}
|
||||
catch(interprocess_exception &){
|
||||
//Correct behaviour
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template < template<class T, bool LazyInit = false, bool Phoenix = true> class IntermoduleType >
|
||||
int phoenix_singleton_test()
|
||||
{
|
||||
typedef int DummyType;
|
||||
typedef IntermoduleType<DummyType, true, true> Tag;
|
||||
typedef Logger<Tag> LoggerType;
|
||||
typedef IntermoduleType<LoggerType, true, true> LoggerSingleton;
|
||||
typedef LogUser<LoggerSingleton> LogUserType;
|
||||
typedef IntermoduleType<LogUserType, true, true> LogUserSingleton;
|
||||
typedef IntermoduleType<LogPhoenixTester<Tag>, true, true> LogPhoenixTesterSingleton;
|
||||
|
||||
//Instantiate Phoenix tester singleton so that it will be destroyed the last
|
||||
LogPhoenixTesterSingleton::get().dummy();
|
||||
|
||||
//Now instantitate a log user singleton
|
||||
LogUserType &log_user = LogUserSingleton::get();
|
||||
|
||||
//Then force LoggerSingleton instantiation
|
||||
//calling a function that will use it.
|
||||
//After main ends, LoggerSingleton will be destroyed
|
||||
//before LogUserSingleton due to LIFO
|
||||
//singleton semantics
|
||||
log_user.function_using_log();
|
||||
|
||||
//Next, LogUserSingleton destructor will resurrect
|
||||
//LoggerSingleton.
|
||||
//After that LoggerSingleton will be destroyed and
|
||||
//lastly LogPhoenixTester will be destroyed checking
|
||||
//LoggerSingleton was correctly destroyed.
|
||||
return 0;
|
||||
}
|
||||
|
||||
template < template<class T, bool LazyInit = false, bool Phoenix = true> class IntermoduleType >
|
||||
int dead_reference_singleton_test()
|
||||
{
|
||||
typedef int DummyType;
|
||||
typedef IntermoduleType<DummyType, true, false> Tag;
|
||||
typedef Logger<Tag> LoggerType;
|
||||
typedef IntermoduleType<LoggerType, true, false> LoggerSingleton;
|
||||
typedef LogDeadReferenceUser<LoggerSingleton> LogDeadReferenceUserType;
|
||||
typedef IntermoduleType<LogDeadReferenceUserType, true, false> LogDeadReferenceUserSingleton;
|
||||
|
||||
//Now instantitate a log user singleton
|
||||
LogDeadReferenceUserType &log_user = LogDeadReferenceUserSingleton::get();
|
||||
|
||||
//Then force LoggerSingleton instantiation
|
||||
//calling a function that will use it.
|
||||
//After main ends, LoggerSingleton will be destroyed
|
||||
//before LogDeadReferenceUserType due to LIFO
|
||||
//singleton semantics
|
||||
log_user.function_using_log();
|
||||
|
||||
//Next, LogDeadReferenceUserType destructor will try to use
|
||||
//LoggerSingleton and an exception will be raised an catched.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
@@ -102,6 +266,20 @@ int main ()
|
||||
}
|
||||
#endif
|
||||
|
||||
//Phoenix singletons are tested after main ends,
|
||||
//LogPhoenixTester does the work
|
||||
phoenix_singleton_test<ipcdetail::portable_intermodule_singleton>();
|
||||
#ifdef BOOST_INTERPROCESS_WINDOWS
|
||||
phoenix_singleton_test<ipcdetail::windows_intermodule_singleton>();
|
||||
#endif
|
||||
|
||||
//Dead reference singletons are tested after main ends,
|
||||
//LogDeadReferenceUser does the work
|
||||
dead_reference_singleton_test<ipcdetail::portable_intermodule_singleton>();
|
||||
#ifdef BOOST_INTERPROCESS_WINDOWS
|
||||
dead_reference_singleton_test<ipcdetail::windows_intermodule_singleton>();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ bool test_types_and_convertions()
|
||||
pcint_t pcint(0);
|
||||
pvint_t pvint(0);
|
||||
pcvint_t pcvint(0);
|
||||
|
||||
|
||||
pint = &dummy_int;
|
||||
pcint = &dummy_int;
|
||||
pvint = &dummy_int;
|
||||
@@ -75,7 +75,7 @@ bool test_arithmetic()
|
||||
typedef intersegment_ptr<int> pint_t;
|
||||
const int NumValues = 5;
|
||||
int values[NumValues];
|
||||
|
||||
|
||||
//Initialize p
|
||||
pint_t p = values;
|
||||
if(p.get() != values)
|
||||
@@ -376,7 +376,7 @@ bool test_multi_segment_shared_memory()
|
||||
shared_memory_object::remove("kk0");
|
||||
managed_multi_shared_memory mshm(create_only, "kk", 4096);
|
||||
}
|
||||
|
||||
|
||||
shared_memory_object::remove("kk0");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -456,12 +456,12 @@ namespace n_report_1
|
||||
{
|
||||
|
||||
class foo: public N::base
|
||||
{
|
||||
{
|
||||
public:
|
||||
|
||||
foo(): m_self(this)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void suicide()
|
||||
{
|
||||
@@ -471,13 +471,13 @@ class foo: public N::base
|
||||
private:
|
||||
|
||||
boost::interprocess::intrusive_ptr<foo, VP> m_self;
|
||||
};
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
boost::interprocess::offset_ptr<foo> foo_ptr = new foo;
|
||||
foo_ptr->suicide();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace n_report_1
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ int list_test (bool copied_allocators_equal = true)
|
||||
shmlist->splice(shmlist->begin(), othershmlist);
|
||||
stdlist->splice(stdlist->begin(), otherstdlist);
|
||||
if(!CheckEqualContainers(shmlist, stdlist))
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
listsize = (int)shmlist->size();
|
||||
|
||||
@@ -48,7 +48,7 @@ int main ()
|
||||
managed_mapped_file mfile(create_only, FileName, FileSize);
|
||||
|
||||
int i;
|
||||
//Let's allocate some memory
|
||||
//Let's allocate some memory
|
||||
for(i = 0; i < max; ++i){
|
||||
array[i] = mfile.allocate(i+1);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ int main ()
|
||||
|
||||
//Construct a vector in the memory-mapped file
|
||||
mfile_vect = mfile.construct<MyVect> ("MyVector") (myallocator);
|
||||
|
||||
|
||||
//Flush cached data from memory-mapped file to disk
|
||||
mfile.flush();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ int main ()
|
||||
managed_shared_memory shmem(create_only, ShmemName, ShmemSize);
|
||||
|
||||
int i;
|
||||
//Let's allocate some memory
|
||||
//Let's allocate some memory
|
||||
for(i = 0; i < max; ++i){
|
||||
array[i] = shmem.allocate(i+1);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ int main ()
|
||||
managed_windows_shared_memory w_shm(create_only, MemName, MemSize);
|
||||
|
||||
int i;
|
||||
//Let's allocate some memory
|
||||
//Let's allocate some memory
|
||||
for(i = 0; i < max; ++i){
|
||||
array[i] = w_shm.allocate(i+1);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ int main ()
|
||||
if(!shmem_vect)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//Destroy and check it is not present
|
||||
w_shm_new.destroy_ptr(w_shm_vect);
|
||||
if(0 != w_shm_new.find<MyVect>("MyVector").first)
|
||||
|
||||
@@ -86,7 +86,7 @@ int main ()
|
||||
managed_xsi_shared_memory shmem(create_only, key, ShmemSize);
|
||||
shmid = shmem.get_shmid();
|
||||
int i;
|
||||
//Let's allocate some memory
|
||||
//Let's allocate some memory
|
||||
for(i = 0; i < max; ++i){
|
||||
array[i] = shmem.allocate(i+1);
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ int map_test ()
|
||||
|
||||
//Shared memory allocator must be always be initialized
|
||||
//since it has no default constructor
|
||||
MyShmMap *shmmap =
|
||||
MyShmMap *shmmap =
|
||||
segment.template construct<MyShmMap>("MyShmMap")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdMap *stdmap = new MyStdMap;
|
||||
|
||||
MyShmMultiMap *shmmultimap =
|
||||
MyShmMultiMap *shmmultimap =
|
||||
segment.template construct<MyShmMultiMap>("MyShmMultiMap")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdMultiMap *stdmultimap = new MyStdMultiMap;
|
||||
|
||||
//Test construction from a range
|
||||
//Test construction from a range
|
||||
{
|
||||
//This is really nasty, but we have no other simple choice
|
||||
IntPairType aux_vect[50];
|
||||
@@ -92,7 +92,7 @@ int map_test ()
|
||||
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
|
||||
}
|
||||
|
||||
MyShmMap *shmmap2 =
|
||||
MyShmMap *shmmap2 =
|
||||
segment.template construct<MyShmMap>("MyShmMap2")
|
||||
( ::boost::make_move_iterator(&aux_vect[0])
|
||||
, ::boost::make_move_iterator(aux_vect + 50)
|
||||
@@ -100,7 +100,7 @@ int map_test ()
|
||||
|
||||
MyStdMap *stdmap2 = new MyStdMap(aux_vect2, aux_vect2 + 50);
|
||||
|
||||
MyShmMultiMap *shmmultimap2 =
|
||||
MyShmMultiMap *shmmultimap2 =
|
||||
segment.template construct<MyShmMultiMap>("MyShmMultiMap2")
|
||||
( ::boost::make_move_iterator(&aux_vect3[0])
|
||||
, ::boost::make_move_iterator(aux_vect3 + 50)
|
||||
@@ -128,7 +128,7 @@ int map_test ()
|
||||
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
|
||||
}
|
||||
|
||||
MyShmMap *shmmap3 =
|
||||
MyShmMap *shmmap3 =
|
||||
segment.template construct<MyShmMap>("MyShmMap3")
|
||||
( ordered_unique_range
|
||||
, ::boost::make_move_iterator(&aux_vect[0])
|
||||
@@ -137,7 +137,7 @@ int map_test ()
|
||||
|
||||
MyStdMap *stdmap3 = new MyStdMap(aux_vect2, aux_vect2 + 50);
|
||||
|
||||
MyShmMultiMap *shmmultimap3 =
|
||||
MyShmMultiMap *shmmultimap3 =
|
||||
segment.template construct<MyShmMultiMap>("MyShmMultiMap3")
|
||||
( ordered_range
|
||||
, ::boost::make_move_iterator(&aux_vect3[0])
|
||||
@@ -508,13 +508,13 @@ int map_test_copyable ()
|
||||
|
||||
//Shared memory allocator must be always be initialized
|
||||
//since it has no default constructor
|
||||
MyShmMap *shmmap =
|
||||
MyShmMap *shmmap =
|
||||
segment.template construct<MyShmMap>("MyShmMap")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdMap *stdmap = new MyStdMap;
|
||||
|
||||
MyShmMultiMap *shmmultimap =
|
||||
MyShmMultiMap *shmmultimap =
|
||||
segment.template construct<MyShmMultiMap>("MyShmMultiMap")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
@@ -555,7 +555,7 @@ int map_test_copyable ()
|
||||
stdmapcopy = *stdmap;
|
||||
shmmmapcopy = *shmmultimap;
|
||||
stdmmapcopy = *stdmultimap;
|
||||
|
||||
|
||||
if(!CheckEqualContainers(&shmmapcopy, &stdmapcopy))
|
||||
return 1;
|
||||
if(!CheckEqualContainers(&shmmmapcopy, &stdmmapcopy))
|
||||
|
||||
@@ -37,7 +37,7 @@ struct file_destroyer
|
||||
~file_destroyer()
|
||||
{
|
||||
//The last destructor will destroy the file
|
||||
file_mapping::remove(get_filename().c_str());
|
||||
file_mapping::remove(get_filename().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,7 +72,7 @@ int main ()
|
||||
test::test_named_creation<mapped_file_creation_test_wrapper>();
|
||||
|
||||
//Create and get name, size and address
|
||||
{
|
||||
{
|
||||
mapped_file file1(create_only, get_filename().c_str(), FileSize, read_write, 0, permissions());
|
||||
|
||||
//Overwrite all memory
|
||||
|
||||
@@ -76,7 +76,7 @@ bool test_allocation(Allocator &a)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
a.all_memory_deallocated() && a.check_sanity();
|
||||
if(!ok) return ok;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ bool test_allocation_shrink(Allocator &a)
|
||||
std::memset(buffers[i], 0, a.size(buffers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Deallocate it in non sequential order
|
||||
for(int j = 0, max = (int)buffers.size()
|
||||
;j < max
|
||||
@@ -170,7 +170,7 @@ bool test_allocation_expand(Allocator &a)
|
||||
preferred_size = min_size*2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Deallocate it in non sequential order
|
||||
for(int j = 0, max = (int)buffers.size()
|
||||
;j < max
|
||||
@@ -243,7 +243,7 @@ bool test_allocation_shrink_and_expand(Allocator &a)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Deallocate it in non sequential order
|
||||
for(int j = 0, max = (int)buffers.size()
|
||||
;j < max
|
||||
@@ -310,7 +310,7 @@ bool test_allocation_deallocation_expand(Allocator &a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Now erase null values from the vector
|
||||
buffers.erase( std::remove(buffers.begin(), buffers.end(), static_cast<void*>(0))
|
||||
, buffers.end());
|
||||
@@ -349,7 +349,7 @@ bool test_allocation_with_reuse(Allocator &a)
|
||||
std::memset(ptr, 0, size);
|
||||
buffers.push_back(ptr);
|
||||
}
|
||||
|
||||
|
||||
//Now deallocate all except the latest
|
||||
//Now try to expand to the double of the sizeof_object
|
||||
for(int i = 0, max = (int)buffers.size() - 1
|
||||
@@ -381,7 +381,7 @@ bool test_allocation_with_reuse(Allocator &a)
|
||||
}
|
||||
//There is only a single block so deallocate it
|
||||
a.deallocate(ptr);
|
||||
|
||||
|
||||
if(!a.all_memory_deallocated() || !a.check_sanity())
|
||||
return false;
|
||||
}
|
||||
@@ -405,7 +405,7 @@ bool test_aligned_allocation(Allocator &a)
|
||||
continue_loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(((std::size_t)ptr & (j - 1)) != 0)
|
||||
return false;
|
||||
a.deallocate(ptr);
|
||||
@@ -441,7 +441,7 @@ bool test_continuous_aligned_allocation(Allocator &a)
|
||||
else{
|
||||
any_allocated = true;
|
||||
}
|
||||
|
||||
|
||||
if(((std::size_t)ptr & (j - 1)) != 0)
|
||||
return false;
|
||||
}
|
||||
@@ -734,7 +734,7 @@ bool test_many_equal_allocation(Allocator &a)
|
||||
buffers2.erase(buffers2.begin()+pos);
|
||||
}
|
||||
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
a.all_memory_deallocated() && a.check_sanity();
|
||||
if(!ok) return ok;
|
||||
}
|
||||
@@ -840,7 +840,7 @@ bool test_many_different_allocation(Allocator &a)
|
||||
buffers2.erase(buffers2.begin()+pos);
|
||||
}
|
||||
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
a.all_memory_deallocated() && a.check_sanity();
|
||||
if(!ok) return ok;
|
||||
}
|
||||
@@ -872,7 +872,7 @@ bool test_many_deallocation(Allocator &a)
|
||||
a.deallocate_many(boost::move(buffers[i]));
|
||||
}
|
||||
buffers.clear();
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
a.all_memory_deallocated() && a.check_sanity();
|
||||
if(!ok) return ok;
|
||||
}
|
||||
@@ -889,7 +889,7 @@ bool test_many_deallocation(Allocator &a)
|
||||
}
|
||||
buffers.clear();
|
||||
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
bool ok = free_memory == a.get_free_memory() &&
|
||||
a.all_memory_deallocated() && a.check_sanity();
|
||||
if(!ok) return ok;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
//This test inserts messages with different priority and marks them with a
|
||||
//This test inserts messages with different priority and marks them with a
|
||||
//time-stamp to check if receiver obtains highest priority messages first and
|
||||
//messages with same priority are received in fifo order
|
||||
bool test_priority_order()
|
||||
@@ -43,7 +43,7 @@ bool test_priority_order()
|
||||
mq2
|
||||
(open_or_create, test::get_process_id_name(), 100, sizeof(std::size_t));
|
||||
|
||||
//We test that the queue is ordered by priority and in the
|
||||
//We test that the queue is ordered by priority and in the
|
||||
//same priority, is a FIFO
|
||||
message_queue::size_type recvd = 0;
|
||||
unsigned int priority = 0;
|
||||
@@ -78,19 +78,19 @@ bool test_priority_order()
|
||||
}
|
||||
|
||||
//[message_queue_test_test_serialize_db
|
||||
//This test creates a in memory data-base using Interprocess machinery and
|
||||
//serializes it through a message queue. Then rebuilds the data-base in
|
||||
//This test creates a in memory data-base using Interprocess machinery and
|
||||
//serializes it through a message queue. Then rebuilds the data-base in
|
||||
//another buffer and checks it against the original data-base
|
||||
bool test_serialize_db()
|
||||
{
|
||||
//Typedef data to create a Interprocess map
|
||||
//Typedef data to create a Interprocess map
|
||||
typedef std::pair<const std::size_t, std::size_t> MyPair;
|
||||
typedef std::less<std::size_t> MyLess;
|
||||
typedef node_allocator<MyPair, managed_external_buffer::segment_manager>
|
||||
node_allocator_t;
|
||||
typedef map<std::size_t,
|
||||
std::size_t,
|
||||
std::less<std::size_t>,
|
||||
typedef map<std::size_t,
|
||||
std::size_t,
|
||||
std::less<std::size_t>,
|
||||
node_allocator_t>
|
||||
MyMap;
|
||||
|
||||
@@ -114,12 +114,12 @@ bool test_serialize_db()
|
||||
|
||||
//Construct the map in the first buffer
|
||||
MyMap *map1 = db_origin.construct<MyMap>("MyMap")
|
||||
(MyLess(),
|
||||
(MyLess(),
|
||||
db_origin.get_segment_manager());
|
||||
if(!map1)
|
||||
return false;
|
||||
|
||||
//Fill map1 until is full
|
||||
//Fill map1 until is full
|
||||
try{
|
||||
std::size_t i = 0;
|
||||
while(1){
|
||||
@@ -135,11 +135,11 @@ bool test_serialize_db()
|
||||
message_queue::size_type total_recvd = 0;
|
||||
unsigned int priority;
|
||||
|
||||
//Send whole first buffer through the mq1, read it
|
||||
//Send whole first buffer through the mq1, read it
|
||||
//through mq2 to the second buffer
|
||||
while(1){
|
||||
//Send a fragment of buffer1 through mq1
|
||||
std::size_t bytes_to_send = MaxMsgSize < (db_origin.get_size() - sent) ?
|
||||
std::size_t bytes_to_send = MaxMsgSize < (db_origin.get_size() - sent) ?
|
||||
MaxMsgSize : (db_origin.get_size() - sent);
|
||||
mq1.send( &static_cast<char*>(db_origin.get_address())[sent]
|
||||
, bytes_to_send
|
||||
@@ -157,8 +157,8 @@ bool test_serialize_db()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//The buffer will contain a copy of the original database
|
||||
|
||||
//The buffer will contain a copy of the original database
|
||||
//so let's interpret the buffer with managed_external_buffer
|
||||
managed_external_buffer db_destiny(open_only, &buffer_destiny[0], BufferSize);
|
||||
|
||||
@@ -188,7 +188,7 @@ bool test_serialize_db()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Destroy maps from db-s
|
||||
db_origin.destroy_ptr(map1);
|
||||
db_destiny.destroy_ptr(map2);
|
||||
@@ -243,15 +243,15 @@ bool test_buffer_overflow()
|
||||
|
||||
int main ()
|
||||
{
|
||||
if(!test_priority_order()){
|
||||
if(!test_priority_order()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_serialize_db()){
|
||||
if(!test_serialize_db()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_buffer_overflow()){
|
||||
if(!test_buffer_overflow()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ class movable_int
|
||||
int m_int;
|
||||
};
|
||||
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
(std::basic_ostream<E, T> & os, movable_int const & p)
|
||||
|
||||
{
|
||||
@@ -93,7 +93,7 @@ class movable_and_copyable_int
|
||||
movable_and_copyable_int(const movable_and_copyable_int& mmi)
|
||||
: m_int(mmi.m_int)
|
||||
{}
|
||||
|
||||
|
||||
movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
|
||||
{ this->m_int = mi.m_int; return *this; }
|
||||
|
||||
@@ -132,8 +132,8 @@ class movable_and_copyable_int
|
||||
int m_int;
|
||||
};
|
||||
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
(std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
|
||||
|
||||
{
|
||||
@@ -155,7 +155,7 @@ class copyable_int
|
||||
copyable_int(const copyable_int& mmi)
|
||||
: m_int(mmi.m_int)
|
||||
{}
|
||||
|
||||
|
||||
copyable_int & operator= (const copyable_int &mi)
|
||||
{ this->m_int = mi.m_int; return *this; }
|
||||
|
||||
@@ -226,8 +226,8 @@ class non_copymovable_int
|
||||
int m_int;
|
||||
};
|
||||
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
template<class E, class T>
|
||||
std::basic_ostream<E, T> & operator<<
|
||||
(std::basic_ostream<E, T> & os, copyable_int const & p)
|
||||
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ void timed_lock_and_sleep(void *arg, M &sm)
|
||||
{
|
||||
data<M> *pdata = static_cast<data<M>*>(arg);
|
||||
boost::posix_time::ptime pt(delay(pdata->m_secs));
|
||||
boost::interprocess::scoped_lock<M>
|
||||
boost::interprocess::scoped_lock<M>
|
||||
l (sm, boost::interprocess::defer_lock);
|
||||
if (l.timed_lock(pt)){
|
||||
boost::thread::sleep(xsecs(2*BaseSeconds));
|
||||
@@ -232,7 +232,7 @@ template<bool SameObject, typename M>
|
||||
void test_mutex_lock()
|
||||
{
|
||||
shared_val = 0;
|
||||
|
||||
|
||||
M m1, m2;
|
||||
M *pm1, *pm2;
|
||||
|
||||
@@ -269,7 +269,7 @@ template<bool SameObject, typename M>
|
||||
void test_mutex_lock_timeout()
|
||||
{
|
||||
shared_val = 0;
|
||||
|
||||
|
||||
M m1, m2;
|
||||
M *pm1, *pm2;
|
||||
|
||||
@@ -392,7 +392,7 @@ inline void test_all_lock()
|
||||
test_trylock<M>()();
|
||||
std::cout << "test_timedlock<" << typeid(M).name() << ">" << std::endl;
|
||||
test_timedlock<M>()();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
inline void test_all_recursive_lock()
|
||||
|
||||
@@ -25,11 +25,11 @@ struct condition_deleter
|
||||
std::string name;
|
||||
|
||||
~condition_deleter()
|
||||
{
|
||||
{
|
||||
if(name.empty())
|
||||
named_condition::remove(test::add_to_process_id_name("named_condition"));
|
||||
else
|
||||
named_condition::remove(name.c_str());
|
||||
named_condition::remove(name.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ class named_condition_test_wrapper
|
||||
public:
|
||||
|
||||
named_condition_test_wrapper()
|
||||
: named_condition(open_or_create,
|
||||
: named_condition(open_or_create,
|
||||
(test::add_to_process_id_name("test_cond") + num_to_string(count)).c_str())
|
||||
{
|
||||
condition_deleter::name += test::add_to_process_id_name("test_cond");
|
||||
@@ -167,11 +167,11 @@ struct mutex_deleter
|
||||
std::string name;
|
||||
|
||||
~mutex_deleter()
|
||||
{
|
||||
{
|
||||
if(name.empty())
|
||||
named_mutex::remove(test::add_to_process_id_name("named_mutex"));
|
||||
else
|
||||
named_mutex::remove(name.c_str());
|
||||
named_mutex::remove(name.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,7 +182,7 @@ class named_mutex_test_wrapper
|
||||
{
|
||||
public:
|
||||
named_mutex_test_wrapper()
|
||||
: named_mutex(open_or_create,
|
||||
: named_mutex(open_or_create,
|
||||
(test::add_to_process_id_name("test_mutex") + num_to_string(count)).c_str())
|
||||
{
|
||||
mutex_deleter::name += test::add_to_process_id_name("test_mutex");
|
||||
|
||||
@@ -86,7 +86,7 @@ int construct_test()
|
||||
{
|
||||
//A special shared memory where we can
|
||||
//construct objects associated with a name.
|
||||
//First remove any old shared memory of the same name, create
|
||||
//First remove any old shared memory of the same name, create
|
||||
//the shared memory segment and initialize needed resources
|
||||
managed_shared_memory segment
|
||||
//create segment name segment size
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace boost { namespace interprocess { namespace test {
|
||||
|
||||
template <class NamedResource>
|
||||
inline void create_then_open_then_open_or_create()
|
||||
{
|
||||
{
|
||||
try{
|
||||
//Create it and open it twice
|
||||
NamedResource nresource1(create_only);
|
||||
@@ -37,7 +37,7 @@ inline void create_then_open_then_open_or_create()
|
||||
|
||||
template <class NamedResource>
|
||||
inline void open_or_create_then_create()
|
||||
{
|
||||
{
|
||||
//Create it with open_or_create and try to create it twice
|
||||
NamedResource nresource1(open_or_create);
|
||||
try{
|
||||
@@ -50,7 +50,7 @@ inline void open_or_create_then_create()
|
||||
|
||||
template <class NamedResource>
|
||||
inline void dont_create_and_open()
|
||||
{
|
||||
{
|
||||
//Try to open it without creating
|
||||
try{
|
||||
NamedResource nresource1(open_only);
|
||||
@@ -72,7 +72,7 @@ inline void test_named_creation()
|
||||
std::cout << "open_or_create_then_create<"
|
||||
<< typeid(NamedResource).name() << ">" << std::endl;
|
||||
open_or_create_then_create<NamedResource>();
|
||||
std::cout << "dont_create_and_open<"
|
||||
std::cout << "dont_create_and_open<"
|
||||
<< typeid(NamedResource).name() << ">" << std::endl;
|
||||
dont_create_and_open<NamedResource>();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ bool test_node_pool<NodePool>::allocate_then_deallocate(NodePool &pool)
|
||||
if((pool.get_real_num_node() - 1) != pool.num_free_nodes()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Now deallocate all and check again
|
||||
for(std::size_t i = 0; i < num_alloc; ++i){
|
||||
pool.deallocate_node(nodes[i]);
|
||||
@@ -59,7 +59,7 @@ bool test_node_pool<NodePool>::allocate_then_deallocate(NodePool &pool)
|
||||
if(4*pool.get_real_num_node() != pool.num_free_nodes()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
pool.deallocate_free_blocks();
|
||||
|
||||
if(0 != pool.num_free_nodes()){
|
||||
@@ -92,7 +92,7 @@ bool test_node_pool<NodePool>::deallocate_free_blocks(NodePool &pool)
|
||||
if(0 != pool.num_free_nodes()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Now deallocate one of each block per iteration
|
||||
for(std::size_t node_i = 0; node_i < nodes_per_block; ++node_i){
|
||||
//Deallocate a node per block
|
||||
@@ -104,7 +104,7 @@ bool test_node_pool<NodePool>::deallocate_free_blocks(NodePool &pool)
|
||||
if(max_blocks*(node_i+1) != pool.num_free_nodes()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Now try to deallocate free blocks
|
||||
pool.deallocate_free_blocks();
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ bool test_types_and_conversions()
|
||||
pcint_t pcint(0);
|
||||
pvint_t pvint(0);
|
||||
pcvint_t pcvint(0);
|
||||
|
||||
|
||||
pint = &dummy_int;
|
||||
pcint = &dummy_int;
|
||||
pvint = &dummy_int;
|
||||
@@ -153,7 +153,7 @@ bool test_arithmetic()
|
||||
typedef offset_ptr<int> pint_t;
|
||||
const int NumValues = 5;
|
||||
int values[NumValues];
|
||||
|
||||
|
||||
//Initialize p
|
||||
pint_t p = values;
|
||||
if(p.get() != values)
|
||||
|
||||
@@ -48,8 +48,8 @@ void PrintContainers(MyShmCont *shmcont, MyStdCont *stdcont)
|
||||
for(; itshm != itshmend; ++itshm){
|
||||
std::cout << *itshm << std::endl;
|
||||
}
|
||||
std::cout << "MyStdCont" << std::endl;
|
||||
|
||||
std::cout << "MyStdCont" << std::endl;
|
||||
|
||||
for(; itstd != itstdend; ++itstd){
|
||||
std::cout << *itstd << std::endl;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ int robust_mutex_test(int argc, char *argv[])
|
||||
std::cout << "robust mutex recovery test" << std::endl;
|
||||
|
||||
//Remove shared memory on construction and destruction
|
||||
class shm_remove
|
||||
class shm_remove
|
||||
{
|
||||
public:
|
||||
shm_remove(){ shared_memory_object::remove
|
||||
@@ -69,7 +69,7 @@ int robust_mutex_test(int argc, char *argv[])
|
||||
while(!*go_ahead){
|
||||
ipcdetail::thread_yield();
|
||||
}
|
||||
|
||||
|
||||
std::cout << "... recovering mutex[0]" << std::endl;
|
||||
//First try to recover lock[0], put into consistent
|
||||
//state and relock it again
|
||||
|
||||
@@ -46,19 +46,19 @@ int set_test ()
|
||||
|
||||
//Shared memory allocator must be always be initialized
|
||||
//since it has no default constructor
|
||||
MyShmSet *shmset =
|
||||
MyShmSet *shmset =
|
||||
segment.template construct<MyShmSet>("MyShmSet")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdSet *stdset = new MyStdSet;
|
||||
|
||||
MyShmMultiSet *shmmultiset =
|
||||
MyShmMultiSet *shmmultiset =
|
||||
segment.template construct<MyShmMultiSet>("MyShmMultiSet")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdMultiSet *stdmultiset = new MyStdMultiSet;
|
||||
|
||||
//Test construction from a range
|
||||
//Test construction from a range
|
||||
{
|
||||
IntType aux_vect[50];
|
||||
for(int i = 0; i < 50; ++i){
|
||||
@@ -75,7 +75,7 @@ int set_test ()
|
||||
aux_vect3[i] = boost::move(move_me);
|
||||
}
|
||||
|
||||
MyShmSet *shmset2 =
|
||||
MyShmSet *shmset2 =
|
||||
segment.template construct<MyShmSet>("MyShmSet2")
|
||||
( ::boost::make_move_iterator(&aux_vect[0])
|
||||
, ::boost::make_move_iterator(aux_vect + 50)
|
||||
@@ -83,7 +83,7 @@ int set_test ()
|
||||
|
||||
MyStdSet *stdset2 = new MyStdSet(aux_vect2, aux_vect2 + 50);
|
||||
|
||||
MyShmMultiSet *shmmultiset2 =
|
||||
MyShmMultiSet *shmmultiset2 =
|
||||
segment.template construct<MyShmMultiSet>("MyShmMultiSet2")
|
||||
( ::boost::make_move_iterator(&aux_vect3[0])
|
||||
, ::boost::make_move_iterator(aux_vect3 + 50)
|
||||
@@ -114,7 +114,7 @@ int set_test ()
|
||||
aux_vect3[i] = boost::move(move_me);
|
||||
}
|
||||
|
||||
MyShmSet *shmset3 =
|
||||
MyShmSet *shmset3 =
|
||||
segment.template construct<MyShmSet>("MyShmSet3")
|
||||
( ordered_unique_range
|
||||
, ::boost::make_move_iterator(&aux_vect[0])
|
||||
@@ -123,7 +123,7 @@ int set_test ()
|
||||
|
||||
MyStdSet *stdset3 = new MyStdSet(aux_vect2, aux_vect2 + 50);
|
||||
|
||||
MyShmMultiSet *shmmultiset3 =
|
||||
MyShmMultiSet *shmmultiset3 =
|
||||
segment.template construct<MyShmMultiSet>("MyShmMultiSet3")
|
||||
( ordered_range
|
||||
, ::boost::make_move_iterator(&aux_vect3[0])
|
||||
@@ -520,13 +520,13 @@ int set_test_copyable ()
|
||||
|
||||
//Shared memory allocator must be always be initialized
|
||||
//since it has no default constructor
|
||||
MyShmSet *shmset =
|
||||
MyShmSet *shmset =
|
||||
segment.template construct<MyShmSet>("MyShmSet")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
MyStdSet *stdset = new MyStdSet;
|
||||
|
||||
MyShmMultiSet *shmmultiset =
|
||||
MyShmMultiSet *shmmultiset =
|
||||
segment.template construct<MyShmMultiSet>("MyShmMultiSet")
|
||||
(std::less<IntType>(), segment.get_segment_manager());
|
||||
|
||||
@@ -567,7 +567,7 @@ int set_test_copyable ()
|
||||
|
||||
shmmsetcopy = *shmmultiset;
|
||||
stdmsetcopy = *stdmultiset;
|
||||
|
||||
|
||||
if(!CheckEqualContainers(&shmmsetcopy, &stdmsetcopy))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ void timed_exclusive(void *arg, SM &sm)
|
||||
{
|
||||
data<SM> *pdata = static_cast<data<SM>*>(arg);
|
||||
boost::posix_time::ptime pt(delay(pdata->m_secs));
|
||||
boost::interprocess::scoped_lock<SM>
|
||||
boost::interprocess::scoped_lock<SM>
|
||||
l (sm, boost::interprocess::defer_lock);
|
||||
if (l.timed_lock(pt)){
|
||||
boost::thread::sleep(xsecs(3*BaseSeconds));
|
||||
@@ -101,7 +101,7 @@ void timed_shared(void *arg, SM &sm)
|
||||
{
|
||||
data<SM> *pdata = static_cast<data<SM>*>(arg);
|
||||
boost::posix_time::ptime pt(delay(pdata->m_secs));
|
||||
boost::interprocess::sharable_lock<SM>
|
||||
boost::interprocess::sharable_lock<SM>
|
||||
l(sm, boost::interprocess::defer_lock);
|
||||
if (l.timed_lock(pt)){
|
||||
if(pdata->m_secs){
|
||||
@@ -196,7 +196,7 @@ void test_plain_sharable_mutex()
|
||||
//We can only assure that the shared will finish first...
|
||||
BOOST_INTERPROCES_CHECK(s1.m_value == 0 || s2.m_value == 0);
|
||||
//...and writers will be mutually excluded after readers
|
||||
BOOST_INTERPROCES_CHECK((e1.m_value == 10 && e2.m_value == 20) ||
|
||||
BOOST_INTERPROCES_CHECK((e1.m_value == 10 && e2.m_value == 20) ||
|
||||
(e1.m_value == 20 && e2.m_value == 10) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ int main ()
|
||||
,FileSize - FileSize/2
|
||||
,0);
|
||||
|
||||
//Fill two regions with a pattern
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
|
||||
@@ -62,7 +62,7 @@ int main ()
|
||||
test::test_named_creation<shared_memory_creation_test_wrapper>();
|
||||
|
||||
//Create and get name, size and address
|
||||
{
|
||||
{
|
||||
shared_memory_object::remove(ShmName);
|
||||
shared_memory shm1(create_only, ShmName, ShmSize, read_write, 0, permissions());
|
||||
|
||||
|
||||
@@ -63,16 +63,16 @@ int simple_test()
|
||||
managed_shared_memory shmem(create_only, process_name.c_str(), 10000);
|
||||
|
||||
{
|
||||
base_shared_ptr s_ptr(base_shared_ptr::pointer(0),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_shared_ptr s_ptr(base_shared_ptr::pointer(0),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_deleter_t(shmem.get_segment_manager()));
|
||||
|
||||
base_shared_ptr s_ptr2(shmem.construct<base_class>("base_class")(),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_shared_ptr s_ptr2(shmem.construct<base_class>("base_class")(),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_deleter_t(shmem.get_segment_manager()));
|
||||
|
||||
base_shared_ptr s_ptr3(offset_ptr<derived_class>(shmem.construct<derived_class>("derived_class")()),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_shared_ptr s_ptr3(offset_ptr<derived_class>(shmem.construct<derived_class>("derived_class")()),
|
||||
base_class_allocator(shmem.get_segment_manager()),
|
||||
base_deleter_t(shmem.get_segment_manager()));
|
||||
|
||||
if(s_ptr3.get_deleter() == 0){
|
||||
@@ -111,20 +111,20 @@ int string_shared_ptr_vector_insertion_test()
|
||||
string_allocator_t;
|
||||
|
||||
//A deleter for shared_ptr<> that erases a shared memory string
|
||||
typedef deleter<string_t, managed_shared_memory::segment_manager>
|
||||
typedef deleter<string_t, managed_shared_memory::segment_manager>
|
||||
string_deleter_t;
|
||||
|
||||
//A shared pointer that points to a shared memory string and its instantiation
|
||||
typedef shared_ptr<string_t, string_allocator_t, string_deleter_t> string_shared_ptr_t;
|
||||
|
||||
//An allocator for shared pointers to a string in shared memory
|
||||
//An allocator for shared pointers to a string in shared memory
|
||||
typedef allocator<string_shared_ptr_t, managed_shared_memory::segment_manager>
|
||||
string_shared_ptr_allocator_t;
|
||||
|
||||
//A weak pointer that points to a shared memory string and its instantiation
|
||||
typedef weak_ptr<string_t, string_allocator_t, string_deleter_t> string_weak_ptr_t;
|
||||
|
||||
//An allocator for weak pointers to a string in shared memory
|
||||
//An allocator for weak pointers to a string in shared memory
|
||||
typedef allocator<string_weak_ptr_t, managed_shared_memory::segment_manager >
|
||||
string_weak_ptr_allocator_t;
|
||||
|
||||
@@ -144,7 +144,7 @@ int string_shared_ptr_vector_insertion_test()
|
||||
{
|
||||
managed_shared_memory shmem(create_only, process_name.c_str(), 20000);
|
||||
|
||||
{
|
||||
{
|
||||
const int NumElements = 100;
|
||||
//Construct the allocator of strings
|
||||
string_allocator_t string_allocator(shmem.get_segment_manager());
|
||||
@@ -202,7 +202,7 @@ int string_shared_ptr_vector_insertion_test()
|
||||
}
|
||||
//Now fill a vector of weak_ptr-s
|
||||
string_weak_ptr_vector_t my_weakptr_vector(string_weak_ptr_allocator);
|
||||
my_weakptr_vector.insert(my_weakptr_vector.begin(), NumElements, string_weak_ptr);
|
||||
my_weakptr_vector.insert(my_weakptr_vector.begin(), NumElements, string_weak_ptr);
|
||||
//The shared count should remain the same
|
||||
if(string_shared_ptr.use_count() != static_cast<long>(my_sharedptr_vector.size()+1)){
|
||||
return 1;
|
||||
@@ -309,28 +309,28 @@ int * get_object()
|
||||
void release_object(int * p)
|
||||
{ BOOST_TEST(p == &cnt); --cnt; }
|
||||
|
||||
template<class T, class A, class D>
|
||||
template<class T, class A, class D>
|
||||
void test_is_X(shared_ptr<T, A, D> const & p)
|
||||
{
|
||||
BOOST_TEST(p->id() == 1);
|
||||
BOOST_TEST((*p).id() == 1);
|
||||
}
|
||||
|
||||
template<class T, class A, class D>
|
||||
template<class T, class A, class D>
|
||||
void test_is_X(weak_ptr<T, A, D> const & p)
|
||||
{
|
||||
BOOST_TEST(p.get() != 0);
|
||||
BOOST_TEST(p.get()->id() == 1);
|
||||
}
|
||||
|
||||
template<class T, class A, class D>
|
||||
template<class T, class A, class D>
|
||||
void test_is_Y(shared_ptr<T, A, D> const & p)
|
||||
{
|
||||
BOOST_TEST(p->id() == 2);
|
||||
BOOST_TEST((*p).id() == 2);
|
||||
}
|
||||
|
||||
template<class T, class A, class D>
|
||||
template<class T, class A, class D>
|
||||
void test_is_Y(weak_ptr<T, A, D> const & p)
|
||||
{
|
||||
shared_ptr<T, A, D> q = p.lock();
|
||||
@@ -338,7 +338,7 @@ void test_is_Y(weak_ptr<T, A, D> const & p)
|
||||
BOOST_TEST(q->id() == 2);
|
||||
}
|
||||
|
||||
template<class T, class T2>
|
||||
template<class T, class T2>
|
||||
void test_eq(T const & a, T2 const & b)
|
||||
{
|
||||
BOOST_TEST(a == b);
|
||||
@@ -347,7 +347,7 @@ void test_eq(T const & a, T2 const & b)
|
||||
BOOST_TEST(!(b < a));
|
||||
}
|
||||
|
||||
template<class T, class T2>
|
||||
template<class T, class T2>
|
||||
void test_ne(T const & a, T2 const & b)
|
||||
{
|
||||
BOOST_TEST(!(a == b));
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
typedef test::dummy_test_allocator<char> DummyCharAllocator;
|
||||
typedef test::dummy_test_allocator<char> DummyCharAllocator;
|
||||
typedef basic_string<char, std::char_traits<char>, DummyCharAllocator> DummyString;
|
||||
typedef test::dummy_test_allocator<DummyString> DummyStringAllocator;
|
||||
typedef test::dummy_test_allocator<wchar_t> DummyWCharAllocator;
|
||||
typedef test::dummy_test_allocator<wchar_t> DummyWCharAllocator;
|
||||
typedef basic_string<wchar_t, std::char_traits<wchar_t>, DummyWCharAllocator> DummyWString;
|
||||
typedef test::dummy_test_allocator<DummyWString> DummyWStringAllocator;
|
||||
|
||||
@@ -54,7 +54,7 @@ template<class StrVector1, class StrVector2>
|
||||
bool CheckEqualStringVector(StrVector1 *strvect1, StrVector2 *strvect2)
|
||||
{
|
||||
StringEqual comp;
|
||||
return std::equal(strvect1->begin(), strvect1->end(),
|
||||
return std::equal(strvect1->begin(), strvect1->end(),
|
||||
strvect2->begin(), comp);
|
||||
}
|
||||
|
||||
@@ -82,13 +82,13 @@ int string_test()
|
||||
(create_only,
|
||||
process_name.c_str(),//segment name
|
||||
65536); //segment size in bytes
|
||||
|
||||
|
||||
ShmemAllocatorChar shmallocator (segment.get_segment_manager());
|
||||
|
||||
//Initialize vector with a range or iterators and allocator
|
||||
ShmStringVector *shmStringVect =
|
||||
ShmStringVector *shmStringVect =
|
||||
segment.construct<ShmStringVector>
|
||||
(anonymous_instance, std::nothrow) //object name
|
||||
(anonymous_instance, std::nothrow) //object name
|
||||
(shmallocator);
|
||||
|
||||
StdStringVector *stdStringVect = new StdStringVector;
|
||||
@@ -113,7 +113,7 @@ int string_test()
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Now push back moving
|
||||
//Now push back moving
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxShmString = "String";
|
||||
auxStdString = "String";
|
||||
@@ -143,7 +143,7 @@ int string_test()
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Now push front moving
|
||||
//Now push front moving
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxShmString = "String";
|
||||
auxStdString = "String";
|
||||
@@ -166,16 +166,16 @@ int string_test()
|
||||
shm_swapper.swap(auxShmString);
|
||||
std_swapper.swap(auxStdString);
|
||||
if(!StringEqual()(auxShmString, auxStdString))
|
||||
return 1;
|
||||
return 1;
|
||||
if(!StringEqual()(shm_swapper, std_swapper))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
shm_swapper.swap(auxShmString);
|
||||
std_swapper.swap(auxStdString);
|
||||
if(!StringEqual()(auxShmString, auxStdString))
|
||||
return 1;
|
||||
return 1;
|
||||
if(!StringEqual()(shm_swapper, std_swapper))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
auxShmString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
|
||||
auxStdString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
|
||||
@@ -184,16 +184,16 @@ int string_test()
|
||||
shm_swapper.swap(auxShmString);
|
||||
std_swapper.swap(auxStdString);
|
||||
if(!StringEqual()(auxShmString, auxStdString))
|
||||
return 1;
|
||||
return 1;
|
||||
if(!StringEqual()(shm_swapper, std_swapper))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
shm_swapper.swap(auxShmString);
|
||||
std_swapper.swap(auxStdString);
|
||||
if(!StringEqual()(auxShmString, auxStdString))
|
||||
return 1;
|
||||
return 1;
|
||||
if(!StringEqual()(shm_swapper, std_swapper))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
//No sort
|
||||
std::sort(shmStringVect->begin(), shmStringVect->end());
|
||||
@@ -207,9 +207,9 @@ int string_test()
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
(*shmStringVect)[i].append(sufix);
|
||||
(*stdStringVect)[i].append(sufix);
|
||||
(*shmStringVect)[i].insert((*shmStringVect)[i].begin(),
|
||||
(*shmStringVect)[i].insert((*shmStringVect)[i].begin(),
|
||||
prefix, prefix + prefix_size);
|
||||
(*stdStringVect)[i].insert((*stdStringVect)[i].begin(),
|
||||
(*stdStringVect)[i].insert((*stdStringVect)[i].begin(),
|
||||
prefix, prefix + prefix_size);
|
||||
}
|
||||
|
||||
@@ -237,10 +237,10 @@ int string_test()
|
||||
if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;
|
||||
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
(*shmStringVect)[i].replace((*shmStringVect)[i].begin(),
|
||||
(*shmStringVect)[i].replace((*shmStringVect)[i].begin(),
|
||||
(*shmStringVect)[i].end(),
|
||||
"String");
|
||||
(*stdStringVect)[i].replace((*stdStringVect)[i].begin(),
|
||||
(*stdStringVect)[i].replace((*stdStringVect)[i].begin(),
|
||||
(*stdStringVect)[i].end(),
|
||||
"String");
|
||||
}
|
||||
|
||||
@@ -42,19 +42,19 @@ typedef basic_managed_shared_memory
|
||||
|
||||
//We will work with narrow characters for shared memory objects
|
||||
//Alias an integer node allocator type
|
||||
typedef allocator<int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<int, my_managed_shared_memory::segment_manager>
|
||||
shmem_allocator_t;
|
||||
typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_node_pair_allocator_t;
|
||||
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_movable_allocator_t;
|
||||
typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_movable_node_pair_allocator_t;
|
||||
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_move_copy_allocator_t;
|
||||
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
|
||||
shmem_copy_allocator_t;
|
||||
typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
|
||||
typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
|
||||
shmem_move_copy_node_pair_allocator_t;
|
||||
|
||||
//Alias standard types
|
||||
@@ -72,28 +72,28 @@ typedef multimap<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMu
|
||||
//Alias movable types
|
||||
typedef set<test::movable_int, std::less<test::movable_int>
|
||||
,shmem_movable_allocator_t> MyMovableShmSet;
|
||||
typedef multiset<test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
typedef multiset<test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
shmem_movable_allocator_t> MyMovableShmMultiSet;
|
||||
typedef map<test::movable_int, test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
typedef map<test::movable_int, test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
shmem_movable_node_pair_allocator_t> MyMovableShmMap;
|
||||
typedef multimap<test::movable_int, test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
typedef multimap<test::movable_int, test::movable_int,
|
||||
std::less<test::movable_int>,
|
||||
shmem_movable_node_pair_allocator_t> MyMovableShmMultiMap;
|
||||
|
||||
typedef set<test::movable_and_copyable_int
|
||||
,std::less<test::movable_and_copyable_int>
|
||||
,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
|
||||
typedef multiset<test::movable_and_copyable_int,
|
||||
std::less<test::movable_and_copyable_int>,
|
||||
typedef multiset<test::movable_and_copyable_int,
|
||||
std::less<test::movable_and_copyable_int>,
|
||||
shmem_move_copy_allocator_t> MyMoveCopyShmMultiSet;
|
||||
|
||||
typedef set<test::copyable_int
|
||||
,std::less<test::copyable_int>
|
||||
,shmem_copy_allocator_t> MyCopyShmSet;
|
||||
typedef multiset<test::copyable_int,
|
||||
std::less<test::copyable_int>,
|
||||
typedef multiset<test::copyable_int,
|
||||
std::less<test::copyable_int>,
|
||||
shmem_copy_allocator_t> MyCopyShmMultiSet;
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ int main()
|
||||
shared_memory_object::remove(process_name.c_str());
|
||||
{
|
||||
managed_shared_memory segment(create_only, process_name.c_str(), 10000);
|
||||
|
||||
|
||||
//Create unique_ptr using dynamic allocation
|
||||
my_unique_ptr_class my_ptr (segment.construct<MyClass>(anonymous_instance)()
|
||||
,segment.get_deleter<MyClass>());
|
||||
@@ -83,7 +83,7 @@ int main()
|
||||
assert(my_ptr2.get() == 0);
|
||||
assert(list.begin()->get() == ptr1);
|
||||
assert(list.rbegin()->get() == ptr2);
|
||||
|
||||
|
||||
//Construct a set and fill
|
||||
typedef std::less<my_unique_ptr_class> set_less_t;
|
||||
MySet set(set_less_t(), segment.get_segment_manager());
|
||||
|
||||
@@ -201,7 +201,7 @@ int main ()
|
||||
heaplist->merge(otherheaplist, std::greater<int>());
|
||||
stdlist->merge(otherstdlist, std::greater<int>());
|
||||
if(!CheckEqual(userlist, stdlist, heaplist)) return 1;
|
||||
|
||||
|
||||
user_buffer.destroy<MyUserList>(L"MyUserList");
|
||||
delete stdlist;
|
||||
|
||||
@@ -212,10 +212,10 @@ int main ()
|
||||
}
|
||||
}
|
||||
catch(boost::interprocess::bad_alloc &){}
|
||||
|
||||
|
||||
MyHeapList::size_type heap_list_size = heaplist->size();
|
||||
|
||||
//Copy heap buffer to another
|
||||
//Copy heap buffer to another
|
||||
const char *insert_beg = static_cast<char*>(heap_buffer.get_address());
|
||||
const char *insert_end = insert_beg + heap_buffer.get_size();
|
||||
std::vector<char> grow_copy (insert_beg, insert_end);
|
||||
@@ -246,7 +246,7 @@ int main ()
|
||||
}
|
||||
catch(boost::interprocess::bad_alloc &){}
|
||||
|
||||
MyUserList::size_type user_list_size = userlist->size();
|
||||
MyUserList::size_type user_list_size = userlist->size();
|
||||
|
||||
if(user_list_size <= heap_list_size){
|
||||
return 1;
|
||||
|
||||
@@ -102,15 +102,15 @@ int vector_test()
|
||||
|
||||
shmvector->resize(100);
|
||||
stdvector->resize(100);
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
|
||||
shmvector->resize(200);
|
||||
stdvector->resize(200);
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
|
||||
shmvector->resize(0);
|
||||
stdvector->resize(0);
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
if(!test::CheckEqualContainers(shmvector, stdvector)) return 1;
|
||||
|
||||
for(int i = 0; i < max; ++i){
|
||||
IntType new_int(i);
|
||||
|
||||
@@ -37,7 +37,7 @@ using namespace boost::interprocess;
|
||||
|
||||
static int vectorstream_test()
|
||||
{
|
||||
{ //Test high watermarking initialization
|
||||
{ //Test high watermarking initialization
|
||||
my_stringstream_t my_stringstream;
|
||||
int a (0);
|
||||
my_stringstream << 11;
|
||||
@@ -45,7 +45,7 @@ static int vectorstream_test()
|
||||
if(a != 11)
|
||||
return 1;
|
||||
}
|
||||
{ //Test high watermarking initialization
|
||||
{ //Test high watermarking initialization
|
||||
my_vectorstream_t my_stringstream;
|
||||
int a (0);
|
||||
my_stringstream << 13;
|
||||
@@ -66,7 +66,7 @@ static int vectorstream_test()
|
||||
my_stringstream << "testline: " << i << std::endl;
|
||||
std_stringstream << "testline: " << i << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if(std::strcmp(my_stringstream.vector().c_str(), std_stringstream.str().c_str()) != 0){
|
||||
return 1;
|
||||
}
|
||||
@@ -75,10 +75,10 @@ static int vectorstream_test()
|
||||
my_stringstream >> str1 >> number1;
|
||||
std_stringstream >> str2 >> number2;
|
||||
if((str1 != str2) || (str1 != str3)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
if((number1 != number2) || (number1 != i)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,10 +105,10 @@ static int vectorstream_test()
|
||||
my_vectorstream >> str1 >> number1;
|
||||
std_stringstream >> str2 >> number2;
|
||||
if((str1 != str2) || (str1 != str3)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
if((number1 != number2) || (number1 != i)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,10 +131,10 @@ static int vectorstream_test()
|
||||
my_stringstream >> str1 >> number1;
|
||||
std_stringstream >> str2 >> number2;
|
||||
if((str1 != str2) || (str1 != str3)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
if((number1 != number2) || (number1 != i)){
|
||||
assert(0); return 1;
|
||||
assert(0); return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ int main ()
|
||||
,FileSize - FileSize/2
|
||||
,0);
|
||||
|
||||
//Fill two regions with a pattern
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
|
||||
@@ -93,7 +93,7 @@ int main (int argc, char *argv[])
|
||||
//Create a mapped region
|
||||
mapped_region region (mapping, read_write, 0, FileSize, 0);
|
||||
|
||||
//Fill two regions with a pattern
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0; i < FileSize; ++i){
|
||||
*filler++ = static_cast<unsigned char>(i);
|
||||
|
||||
Reference in New Issue
Block a user