diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index 88735d1..740716b 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -70,7 +70,6 @@ to avoid Boost from trying to automatically link the [*Boost.DateTime]. * GCC 3.4.4 Cygwin * Intel 9.1 Windows XP * GCC 4.1.2 Linux -* Codewarrior 9.4 Windows XP * GCC 3.4.3 Solaris 11 * GCC 4.0 MacOs 10.4.1 @@ -6336,24 +6335,6 @@ documentation. Hewlett-Packard Company makes no representations about the suitab of this software for any purpose. It is provided "as is" without express or implied warranty. -[*Boost.Interprocess] atomic integer manipulation functions are based on -Apache Portable Runtime: - -Copyright 2000-2005 The Apache Software Foundation or its licensors, as -applicable. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - [endsect] [endsect] diff --git a/example/doc_anonymous_upgradable_mutexA.cpp b/example/doc_anonymous_upgradable_mutexA.cpp index 29ca49c..5cd7865 100644 --- a/example/doc_anonymous_upgradable_mutexA.cpp +++ b/example/doc_anonymous_upgradable_mutexA.cpp @@ -74,4 +74,4 @@ int main () return 0; } -//] \ No newline at end of file +//] diff --git a/proj/cygwin/MakeAll b/proj/cygwin/MakeAll index bb5a269..4073873 100644 --- a/proj/cygwin/MakeAll +++ b/proj/cygwin/MakeAll @@ -5,23 +5,17 @@ endif BOOST_ROOT=../../../.. -INTERPROCESS_CPP := $(wildcard ../../src/*.cpp) -INTERPROCESS_OBJ := $(patsubst ../../src/%.cpp, lib_%.o, $(INTERPROCESS_CPP)) - INTERPROCESSTEST_CPP := $(wildcard ../../test/*.cpp) INTERPROCESSTEST_OUT := $(patsubst ../../test/%.cpp, ../../bin/cygwin/test_%.out, $(INTERPROCESSTEST_CPP)) -INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/cygwin/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) - -INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) -INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/cygwin/ex__%.out, $(INTERPROCESSEXAMPLE_CPP)) +#INTERPROCESSEXAMPLE_CPP := $(wildcard ../../example/*.cpp) +#INTERPROCESSEXAMPLE_OUT := $(patsubst ../../example/%.cpp, ../../bin/cygwin/ex_%.out, $(INTERPROCESSEXAMPLE_CPP)) LIBDIR:= ../../../../stage/lib .PHONY: createdir clean -all: createdir $(INTERPROCESSEXAMPLE_OUT) $(INTERPROCESSTEST_OUT) $(INTERPROCESSEXAMPLE_OUT) +all: createdir $(INTERPROCESSEXAMPLE_OUT) $(INTERPROCESSTEST_OUT) @cd . createdir: @@ -30,8 +24,8 @@ createdir: ../../bin/cygwin/test_%.out: ../../test/%.cpp $(CC) -g $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR) -lboost_thread-gcc-mt -I$(BOOST_ROOT) -lstdc++ -o $@ -../../bin/cygwin/ex_%.out: ../../example/%.cpp - $(CC) -g $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR)-lboost_thread-gcc-mt -I$(BOOST_ROOT) -lstdc++ -o $@ +#../../bin/cygwin/ex_%.out: ../../example/%.cpp +# $(CC) -g $< -Wall -DBOOST_DATE_TIME_NO_LIB -L$(LIBDIR)-lboost_thread-gcc-mt -I$(BOOST_ROOT) -lstdc++ -o $@ clean: diff --git a/proj/vc7ide/Interprocess.sln b/proj/vc7ide/Interprocess.sln index 158dfd3..0c7730a 100644 --- a/proj/vc7ide/Interprocess.sln +++ b/proj/vc7ide/Interprocess.sln @@ -403,6 +403,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_shared_ptr", "doc_share ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "managed_shared_memory_test", "managed_shared_memory.vcproj", "{58DF28E3-0926-F47A-E28A-B03A4D619631}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -815,6 +819,10 @@ Global {51CE89A3-6092-F4EA-48A7-B4B9AC326093}.Debug.Build.0 = Debug|Win32 {51CE89A3-6092-F4EA-48A7-B4B9AC326093}.Release.ActiveCfg = Release|Win32 {51CE89A3-6092-F4EA-48A7-B4B9AC326093}.Release.Build.0 = Release|Win32 + {58DF28E3-0926-F47A-E28A-B03A4D619631}.Debug.ActiveCfg = Debug|Win32 + {58DF28E3-0926-F47A-E28A-B03A4D619631}.Debug.Build.0 = Debug|Win32 + {58DF28E3-0926-F47A-E28A-B03A4D619631}.Release.ActiveCfg = Release|Win32 + {58DF28E3-0926-F47A-E28A-B03A4D619631}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/interprocesslib.vcproj b/proj/vc7ide/interprocesslib.vcproj index 3263916..429ce55 100644 --- a/proj/vc7ide/interprocesslib.vcproj +++ b/proj/vc7ide/interprocesslib.vcproj @@ -386,6 +386,9 @@ + + diff --git a/proj/vc7ide/managed_shared_memory.vcproj b/proj/vc7ide/managed_shared_memory.vcproj new file mode 100644 index 0000000..528972d --- /dev/null +++ b/proj/vc7ide/managed_shared_memory.vcproj @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/deque_test.cpp b/test/deque_test.cpp index c8a6b8d..c9a6934 100644 --- a/test/deque_test.cpp +++ b/test/deque_test.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "get_process_id_name.hpp" @@ -177,7 +178,6 @@ bool do_test() } if(!copyable_only(shmdeque, stddeque -// ,boost::integral_constant ,detail::bool_::value>())){ return false; } diff --git a/test/managed_mapped_file_test.cpp b/test/managed_mapped_file_test.cpp index 17c76ac..c33b97e 100644 --- a/test/managed_mapped_file_test.cpp +++ b/test/managed_mapped_file_test.cpp @@ -79,6 +79,25 @@ int main () mfile.flush(); } { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + + //Check vector is still there + MyVect *mfile_vect = mfile.find("MyVector").first; + if(!mfile_vect) + return -1; + } + + { + std::size_t old_free_memory; + { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + old_free_memory = mfile.get_free_memory(); + } + + //Now grow the file + managed_mapped_file::grow(FileName, FileSize); //Map preexisting file again in memory managed_mapped_file mfile(open_only, FileName); @@ -88,11 +107,63 @@ int main () if(!mfile_vect) return -1; - //Destroy and check it is not present - mfile.destroy_ptr(mfile_vect); - if(0 != mfile.find("MyVector").first) + if(mfile.get_size() != (FileSize*2)) + return -1; + if(mfile.get_free_memory() <= old_free_memory) return -1; } + { + std::size_t old_free_memory, next_free_memory, + old_file_size, next_file_size, final_file_size; + { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + old_free_memory = mfile.get_free_memory(); + old_file_size = mfile.get_size(); + } + + //Now shrink the file + managed_mapped_file::shrink_to_fit(FileName); + + { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + next_file_size = mfile.get_size(); + + //Check vector is still there + MyVect *mfile_vect = mfile.find("MyVector").first; + if(!mfile_vect) + return -1; + + next_free_memory = mfile.get_free_memory(); + if(next_free_memory >= old_free_memory) + return -1; + if(old_file_size <= next_file_size) + return -1; + } + + //Now destroy the vector + { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + + //Destroy and check it is not present + mfile.destroy("MyVector"); + if(0 != mfile.find("MyVector").first) + return -1; + } + + //Now shrink the file + managed_mapped_file::shrink_to_fit(FileName); + { + //Map preexisting file again in memory + managed_mapped_file mfile(open_only, FileName); + final_file_size = mfile.get_size(); + if(next_file_size <= final_file_size) + return -1; + } + } + std::remove(FileName); return 0; } diff --git a/test/managed_shared_memory_test.cpp b/test/managed_shared_memory_test.cpp new file mode 100644 index 0000000..9d7d94c --- /dev/null +++ b/test/managed_shared_memory_test.cpp @@ -0,0 +1,168 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2007. Distributed under 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) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include "get_process_id_name.hpp" + +using namespace boost::interprocess; + +int main () +{ + const int ShmemSize = 65536; + const char *const ShmemName = test::get_process_id_name(); + + //STL compatible allocator object for memory-mapped shmem + typedef allocator + allocator_int_t; + //A vector that uses that allocator + typedef boost::interprocess::vector MyVect; + + { + //Remove the shmem it is already created + shared_memory_object::remove(ShmemName); + + const int max = 100; + void *array[max]; + //Named allocate capable shared memory allocator + managed_shared_memory shmem(create_only, ShmemName, ShmemSize); + + int i; + //Let's allocate some memory + for(i = 0; i < max; ++i){ + array[i] = shmem.allocate(i+1); + } + + //Deallocate allocated memory + for(i = 0; i < max; ++i){ + shmem.deallocate(array[i]); + } + } + + { + //Remove the shmem it is already created + shared_memory_object::remove(ShmemName); + + //Named allocate capable memory mapped shmem managed memory class + managed_shared_memory shmem(create_only, ShmemName, ShmemSize); + + //Construct the STL-like allocator with the segment manager + const allocator_int_t myallocator (shmem.get_segment_manager()); + + //Construct vector + MyVect *shmem_vect = shmem.construct ("MyVector") (myallocator); + + //Test that vector can be found via name + if(shmem_vect != shmem.find("MyVector").first) + return -1; + + //Destroy and check it is not present + shmem.destroy ("MyVector"); + if(0 != shmem.find("MyVector").first) + return -1; + + //Construct a vector in the memory-mapped shmem + shmem_vect = shmem.construct ("MyVector") (myallocator); + } + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + + //Check vector is still there + MyVect *shmem_vect = shmem.find("MyVector").first; + if(!shmem_vect) + return -1; + } + + { + std::size_t old_free_memory; + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + old_free_memory = shmem.get_free_memory(); + } + + //Now grow the shmem + managed_shared_memory::grow(ShmemName, ShmemSize); + + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + + //Check vector is still there + MyVect *shmem_vect = shmem.find("MyVector").first; + if(!shmem_vect) + return -1; + + if(shmem.get_size() != (ShmemSize*2)) + return -1; + if(shmem.get_free_memory() <= old_free_memory) + return -1; + } + { + std::size_t old_free_memory, next_free_memory, + old_shmem_size, next_shmem_size, final_shmem_size; + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + old_free_memory = shmem.get_free_memory(); + old_shmem_size = shmem.get_size(); + } + + //Now shrink the shmem + managed_shared_memory::shrink_to_fit(ShmemName); + + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + next_shmem_size = shmem.get_size(); + + //Check vector is still there + MyVect *shmem_vect = shmem.find("MyVector").first; + if(!shmem_vect) + return -1; + + next_free_memory = shmem.get_free_memory(); + if(next_free_memory >= old_free_memory) + return -1; + if(old_shmem_size <= next_shmem_size) + return -1; + } + + //Now destroy the vector + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + + //Destroy and check it is not present + shmem.destroy("MyVector"); + if(0 != shmem.find("MyVector").first) + return -1; + } + + //Now shrink the shmem + managed_shared_memory::shrink_to_fit(ShmemName); + { + //Map preexisting shmem again in memory + managed_shared_memory shmem(open_only, ShmemName); + final_shmem_size = shmem.get_size(); + if(next_shmem_size <= final_shmem_size) + return -1; + } + } + + shared_memory_object::remove(ShmemName); + return 0; +} + +#include diff --git a/test/mapped_file_test.cpp b/test/mapped_file_test.cpp index 06a05f5..233e907 100644 --- a/test/mapped_file_test.cpp +++ b/test/mapped_file_test.cpp @@ -73,7 +73,7 @@ int main () } //Overwrite all memory - std::memset(file1.get_address(), 0, file1.get_size()); + std::memset(file1.get_user_address(), 0, file1.get_user_size()); } std::remove(FileName); return 0; diff --git a/test/named_allocation_test_template.hpp b/test/named_allocation_test_template.hpp index a4ce3e9..7cb60bc 100644 --- a/test/named_allocation_test_template.hpp +++ b/test/named_allocation_test_template.hpp @@ -28,6 +28,14 @@ namespace boost { namespace interprocess { namespace test { +namespace { + const wchar_t *get_prefix(wchar_t) + { return L"prefix_name_"; } + + const char *get_prefix(char) + { return "prefix_name_"; } +} + //This test allocates until there is no more memory //and after that deallocates all in the same order template @@ -43,7 +51,7 @@ bool test_names_and_types(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); @@ -105,7 +113,7 @@ bool test_named_iterators(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); if(!ptr) break; @@ -175,7 +183,7 @@ bool test_shrink_to_fit(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); @@ -215,7 +223,7 @@ bool test_direct_named_allocation_destruction(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); if(!ptr) break; @@ -257,7 +265,7 @@ bool test_named_allocation_inverse_destruction(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); if(!ptr) break; @@ -297,7 +305,7 @@ bool test_named_allocation_mixed_destruction(ManagedMemory &m) for(int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); if(!ptr) break; @@ -339,7 +347,7 @@ bool test_inverse_named_allocation_destruction(ManagedMemory &m) for(unsigned int i = 0; true; ++i){ formatter.seekp(0); - formatter << "prefix_name_" << i << std::ends; + formatter << get_prefix(char_type()) << i << std::ends; char *ptr = m.template construct(name, std::nothrow)(i); if(!ptr) break; @@ -426,6 +434,7 @@ template