diff --git a/include/boost/interprocess/allocators/adaptive_pool.hpp b/include/boost/interprocess/allocators/adaptive_pool.hpp index 479856e..10dded6 100644 --- a/include/boost/interprocess/allocators/adaptive_pool.hpp +++ b/include/boost/interprocess/allocators/adaptive_pool.hpp @@ -81,7 +81,13 @@ class adaptive_pool_base struct node_pool { typedef ipcdetail::shared_adaptive_node_pool - < SegmentManager, sizeof_value::value, NodesPerBlock, MaxFreeBlocks, OverheadPercent> type; + < SegmentManager + , sizeof_value::value + , NodesPerBlock + , MaxFreeBlocks + , OverheadPercent + , alignof_value::value + > type; static type *get(void *p) { return static_cast(p); } diff --git a/include/boost/interprocess/allocators/cached_adaptive_pool.hpp b/include/boost/interprocess/allocators/cached_adaptive_pool.hpp index 40e4631..5cf84d7 100644 --- a/include/boost/interprocess/allocators/cached_adaptive_pool.hpp +++ b/include/boost/interprocess/allocators/cached_adaptive_pool.hpp @@ -56,6 +56,7 @@ class cached_adaptive_pool_v1 , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > , 1> { @@ -69,6 +70,7 @@ class cached_adaptive_pool_v1 , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > , 1> base_t; @@ -146,6 +148,7 @@ class cached_adaptive_pool , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > , 2> #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED @@ -161,6 +164,7 @@ class cached_adaptive_pool , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > , 2> base_t; diff --git a/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp b/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp index e9a8e26..c2a3ef9 100644 --- a/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp +++ b/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp @@ -46,6 +46,7 @@ template< class SegmentManager , std::size_t NodesPerBlock , std::size_t MaxFreeBlocks , unsigned char OverheadPercent + , std::size_t NodeAlign > class private_adaptive_node_pool : public boost::container::dtl::private_adaptive_node_pool_impl_rt @@ -68,11 +69,12 @@ class private_adaptive_node_pool typedef SegmentManager segment_manager; typedef typename base_t::size_type size_type; - static const size_type nodes_per_block = NodesPerBlock; + BOOST_STATIC_CONSTEXPR size_type nodes_per_block = NodesPerBlock; + BOOST_STATIC_CONSTEXPR std::size_t node_alignment = NodeAlign != 0 ? NodeAlign : 1u; //!Constructor from a segment manager. Never throws private_adaptive_node_pool(segment_manager *segment_mngr) - : base_t(segment_mngr, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent) + : base_t(segment_mngr, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent, NodeAlign) {} //!Returns the segment manager. Never throws @@ -89,16 +91,17 @@ template< class SegmentManager , std::size_t NodesPerBlock , std::size_t MaxFreeBlocks , unsigned char OverheadPercent + , std::size_t NodeAlign > class shared_adaptive_node_pool : public ipcdetail::shared_pool_impl < private_adaptive_node_pool - + > { typedef ipcdetail::shared_pool_impl < private_adaptive_node_pool - + > base_t; public: shared_adaptive_node_pool(SegmentManager *segment_mgnr) diff --git a/include/boost/interprocess/allocators/private_adaptive_pool.hpp b/include/boost/interprocess/allocators/private_adaptive_pool.hpp index 6871ba5..b8a3afc 100644 --- a/include/boost/interprocess/allocators/private_adaptive_pool.hpp +++ b/include/boost/interprocess/allocators/private_adaptive_pool.hpp @@ -80,6 +80,7 @@ class private_adaptive_pool_base , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > node_pool_t; BOOST_INTERPROCESS_STATIC_ASSERT((Version <=2)); @@ -125,6 +126,7 @@ class private_adaptive_pool_base , NodesPerBlock , MaxFreeBlocks , OverheadPercent + , alignof_value::value > type; static type *get(void *p) diff --git a/test/adaptive_node_pool_test.cpp b/test/adaptive_node_pool_test.cpp index 13afdb4..0dc88ea 100644 --- a/test/adaptive_node_pool_test.cpp +++ b/test/adaptive_node_pool_test.cpp @@ -17,11 +17,49 @@ typedef managed_shared_memory::segment_manager segment_manager_t; int main () { - typedef ipcdetail::private_adaptive_node_pool - node_pool_t; + { //Private, normal alignment, small data + typedef ipcdetail::private_adaptive_node_pool + node_pool_t; - if(!test::test_all_node_pool()) - return 1; + if (!test::test_all_node_pool()) + return 1; + } + { //Private, small alignment, small data + typedef ipcdetail::private_adaptive_node_pool + node_pool_t; + + if (!test::test_all_node_pool()) + return 1; + } + { //Private, normal alignment + typedef ipcdetail::private_adaptive_node_pool + node_pool_t; + + if (!test::test_all_node_pool()) + return 1; + } + { //Private, overaligned + typedef ipcdetail::private_adaptive_node_pool + node_pool_t; + + if (!test::test_all_node_pool()) + return 1; + } + + { //Shared, normal alignment + typedef ipcdetail::shared_adaptive_node_pool + node_pool_t; + + if (!test::test_all_node_pool()) + return 1; + } + { //Shared, overaligned + typedef ipcdetail::shared_adaptive_node_pool + node_pool_t; + + if (!test::test_all_node_pool()) + return 1; + } return 0; } diff --git a/test/adaptive_pool_test.cpp b/test/adaptive_pool_test.cpp index 53cd384..f7946b7 100644 --- a/test/adaptive_pool_test.cpp +++ b/test/adaptive_pool_test.cpp @@ -12,14 +12,14 @@ #include #include #include -#include "print_container.hpp" -#include "dummy_test_allocator.hpp" #include "movable_int.hpp" #include "list_test.hpp" #include "vector_test.hpp" using namespace boost::interprocess; +typedef test::overaligned_copyable_int oint_t; + //We will work with wide characters for shared memory objects //Alias an adaptive pool that allocates ints typedef adaptive_pool @@ -28,16 +28,23 @@ typedef adaptive_pool typedef ipcdetail::adaptive_pool_v1 shmem_node_allocator_v1_t; +typedef adaptive_pool + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_t; +typedef ipcdetail::adaptive_pool_v1 + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_v1_t; + namespace boost { namespace interprocess { //Explicit instantiations to catch compilation errors template class adaptive_pool; +template class adaptive_pool; template class adaptive_pool; namespace ipcdetail { template class ipcdetail::adaptive_pool_v1; +template class ipcdetail::adaptive_pool_v1; template class ipcdetail::adaptive_pool_v1; }}} @@ -45,24 +52,36 @@ template class ipcdetail::adaptive_pool_v1 MyShmList; typedef boost::container::list MyShmListV1; +typedef boost::container::list MyOShmList; +typedef boost::container::list MyOShmListV1; //Alias vector types typedef boost::container::vector MyShmVector; typedef boost::container::vector MyShmVectorV1; +typedef boost::container::vector MyOShmVector; +typedef boost::container::vector MyOShmVectorV1; int main () { if(test::list_test()) return 1; - if(test::list_test()) return 1; + if(test::list_test()) + return 1; + if(test::list_test()) + return 1; + if(test::vector_test()) return 1; - if(test::vector_test()) return 1; + if(test::vector_test()) + return 1; + if(test::vector_test()) + return 1; + return 0; } diff --git a/test/cached_adaptive_pool_test.cpp b/test/cached_adaptive_pool_test.cpp index 238184f..cd16874 100644 --- a/test/cached_adaptive_pool_test.cpp +++ b/test/cached_adaptive_pool_test.cpp @@ -12,59 +12,74 @@ #include #include #include -#include "print_container.hpp" -#include "dummy_test_allocator.hpp" #include "movable_int.hpp" #include "list_test.hpp" #include "vector_test.hpp" using namespace boost::interprocess; -//We will work with wide characters for shared memory objects -//Alias an cached adaptive pool that allocates ints -typedef cached_adaptive_pool - - cached_node_allocator_t; +typedef test::overaligned_copyable_int oint_t; +//We will work with wide characters for shared memory objects +//Alias an integer node allocator type +typedef cached_adaptive_pool + priv_node_allocator_t; typedef ipcdetail::cached_adaptive_pool_v1 - - cached_node_allocator_v1_t; + priv_node_allocator_v1_t; +typedef cached_adaptive_pool + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_t; +typedef ipcdetail::cached_adaptive_pool_v1 + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_v1_t; namespace boost { namespace interprocess { //Explicit instantiations to catch compilation errors template class cached_adaptive_pool; +template class cached_adaptive_pool; template class cached_adaptive_pool; namespace ipcdetail { template class ipcdetail::cached_adaptive_pool_v1; +template class ipcdetail::cached_adaptive_pool_v1; template class ipcdetail::cached_adaptive_pool_v1; }}} //Alias list types -typedef boost::container::list MyShmList; -typedef boost::container::list MyShmListV1; +typedef boost::container::list MyShmList; +typedef boost::container::list MyShmListV1; +typedef boost::container::list MyOShmList; +typedef boost::container::list MyOShmListV1; //Alias vector types -typedef boost::container::vector MyShmVector; -typedef boost::container::vector MyShmVectorV1; +typedef boost::container::vector MyShmVector; +typedef boost::container::vector MyShmVectorV1; +typedef boost::container::vector MyOShmVector; +typedef boost::container::vector MyOShmVectorV1; int main () { - if(test::list_test()) + if(test::list_test(false)) + return 1; + if(test::list_test(false)) return 1; - if(test::list_test()) + if(test::list_test()) + return 1; + if(test::list_test()) return 1; if(test::vector_test()) return 1; - if(test::vector_test()) return 1; + if(test::vector_test()) + return 1; + if(test::vector_test()) + return 1; + return 0; } diff --git a/test/private_adaptive_pool_test.cpp b/test/private_adaptive_pool_test.cpp index 9a9bd43..4630fc7 100644 --- a/test/private_adaptive_pool_test.cpp +++ b/test/private_adaptive_pool_test.cpp @@ -12,42 +12,52 @@ #include #include #include -#include "print_container.hpp" -#include "dummy_test_allocator.hpp" #include "movable_int.hpp" #include "list_test.hpp" #include "vector_test.hpp" using namespace boost::interprocess; +typedef test::overaligned_copyable_int oint_t; + //We will work with wide characters for shared memory objects -//Alias a private adaptive pool that allocates ints +//Alias an integer node allocator type typedef private_adaptive_pool priv_node_allocator_t; typedef ipcdetail::private_adaptive_pool_v1 priv_node_allocator_v1_t; +typedef private_adaptive_pool + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_t; +typedef ipcdetail::private_adaptive_pool_v1 + < oint_t, managed_shared_memory::segment_manager> shmem_onode_allocator_v1_t; namespace boost { namespace interprocess { //Explicit instantiations to catch compilation errors template class private_adaptive_pool; +template class private_adaptive_pool; template class private_adaptive_pool; namespace ipcdetail { template class ipcdetail::private_adaptive_pool_v1; +template class ipcdetail::private_adaptive_pool_v1; template class ipcdetail::private_adaptive_pool_v1; }}} //Alias list types -typedef boost::container::list MyShmList; -typedef boost::container::list MyShmListV1; +typedef boost::container::list MyShmList; +typedef boost::container::list MyShmListV1; +typedef boost::container::list MyOShmList; +typedef boost::container::list MyOShmListV1; //Alias vector types typedef boost::container::vector MyShmVector; typedef boost::container::vector MyShmVectorV1; +typedef boost::container::vector MyOShmVector; +typedef boost::container::vector MyOShmVectorV1; int main () { @@ -55,9 +65,21 @@ int main () return 1; if(test::list_test(false)) return 1; + + if(test::list_test(false)) + return 1; + if(test::list_test(false)) + return 1; + if(test::vector_test()) return 1; if(test::vector_test()) return 1; + + if(test::vector_test()) + return 1; + if(test::vector_test()) + return 1; + return 0; }