mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Allow adaptive pool based classes to support overaligned types. This change requires adding the node alignment data thorough the class inheritance and complicating a bit the logic for the adaptive pool. Overalignment value is packed inside free bits of existing bits in order to avoid breaking ABI.
This commit is contained in:
@@ -81,7 +81,13 @@ class adaptive_pool_base
|
||||
struct node_pool
|
||||
{
|
||||
typedef ipcdetail::shared_adaptive_node_pool
|
||||
< SegmentManager, sizeof_value<T>::value, NodesPerBlock, MaxFreeBlocks, OverheadPercent> type;
|
||||
< SegmentManager
|
||||
, sizeof_value<T>::value
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
> type;
|
||||
|
||||
static type *get(void *p)
|
||||
{ return static_cast<type*>(p); }
|
||||
|
||||
@@ -56,6 +56,7 @@ class cached_adaptive_pool_v1
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
>
|
||||
, 1>
|
||||
{
|
||||
@@ -69,6 +70,7 @@ class cached_adaptive_pool_v1
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
>
|
||||
, 1> base_t;
|
||||
|
||||
@@ -146,6 +148,7 @@ class cached_adaptive_pool
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
>
|
||||
, 2>
|
||||
#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
||||
@@ -161,6 +164,7 @@ class cached_adaptive_pool
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
>
|
||||
, 2> base_t;
|
||||
|
||||
|
||||
@@ -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
|
||||
<SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent>
|
||||
<SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent, NodeAlign>
|
||||
>
|
||||
{
|
||||
typedef ipcdetail::shared_pool_impl
|
||||
< private_adaptive_node_pool
|
||||
<SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent>
|
||||
<SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent, NodeAlign>
|
||||
> base_t;
|
||||
public:
|
||||
shared_adaptive_node_pool(SegmentManager *segment_mgnr)
|
||||
|
||||
@@ -80,6 +80,7 @@ class private_adaptive_pool_base
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
> node_pool_t;
|
||||
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((Version <=2));
|
||||
@@ -125,6 +126,7 @@ class private_adaptive_pool_base
|
||||
, NodesPerBlock
|
||||
, MaxFreeBlocks
|
||||
, OverheadPercent
|
||||
, alignof_value<T>::value
|
||||
> type;
|
||||
|
||||
static type *get(void *p)
|
||||
|
||||
@@ -17,11 +17,49 @@ typedef managed_shared_memory::segment_manager segment_manager_t;
|
||||
|
||||
int main ()
|
||||
{
|
||||
{ //Private, normal alignment, small data
|
||||
typedef ipcdetail::private_adaptive_node_pool
|
||||
<segment_manager_t, 4, 64, 64, 5> node_pool_t;
|
||||
<segment_manager_t, 1u, 64, 64, 5, 0> node_pool_t;
|
||||
|
||||
if(!test::test_all_node_pool<node_pool_t>())
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
{ //Private, small alignment, small data
|
||||
typedef ipcdetail::private_adaptive_node_pool
|
||||
<segment_manager_t, 1u, 64, 64, 5, 2> node_pool_t;
|
||||
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
{ //Private, normal alignment
|
||||
typedef ipcdetail::private_adaptive_node_pool
|
||||
<segment_manager_t, sizeof(void*), 64, 64, 5, 0> node_pool_t;
|
||||
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
{ //Private, overaligned
|
||||
typedef ipcdetail::private_adaptive_node_pool
|
||||
<segment_manager_t, sizeof(void*), 64, 64, 5, sizeof(void*)*4U> node_pool_t;
|
||||
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
|
||||
{ //Shared, normal alignment
|
||||
typedef ipcdetail::shared_adaptive_node_pool
|
||||
<segment_manager_t, 4u, 64, 64, 5, 0> node_pool_t;
|
||||
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
{ //Shared, overaligned
|
||||
typedef ipcdetail::shared_adaptive_node_pool
|
||||
<segment_manager_t, sizeof(void*), 64, 64, 5, sizeof(void*) * 4u> node_pool_t;
|
||||
|
||||
if (!test::test_all_node_pool<node_pool_t>())
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
#include <boost/container/list.hpp>
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/interprocess/allocators/adaptive_pool.hpp>
|
||||
#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
|
||||
<int, managed_shared_memory::segment_manager> 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<int, managed_shared_memory::segment_manager>;
|
||||
template class adaptive_pool<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class adaptive_pool<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
namespace ipcdetail {
|
||||
|
||||
template class ipcdetail::adaptive_pool_v1<int, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::adaptive_pool_v1<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::adaptive_pool_v1<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
}}}
|
||||
@@ -45,24 +52,36 @@ template class ipcdetail::adaptive_pool_v1<void, managed_shared_memory::segment_
|
||||
//Alias list types
|
||||
typedef boost::container::list<int, shmem_node_allocator_t> MyShmList;
|
||||
typedef boost::container::list<int, shmem_node_allocator_v1_t> MyShmListV1;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_t> MyOShmList;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_v1_t> MyOShmListV1;
|
||||
|
||||
//Alias vector types
|
||||
typedef boost::container::vector<int, shmem_node_allocator_t> MyShmVector;
|
||||
typedef boost::container::vector<int, shmem_node_allocator_v1_t> MyShmVectorV1;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_t> MyOShmVector;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_v1_t> MyOShmVectorV1;
|
||||
|
||||
int main ()
|
||||
{
|
||||
if(test::list_test<managed_shared_memory, MyShmList, true>())
|
||||
return 1;
|
||||
|
||||
if(test::list_test<managed_shared_memory, MyShmListV1, true>())
|
||||
return 1;
|
||||
|
||||
if(test::list_test<managed_shared_memory, MyOShmList, true>())
|
||||
return 1;
|
||||
if(test::list_test<managed_shared_memory, MyOShmListV1, true>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyShmVector>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVector>())
|
||||
return 1;
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,59 +12,74 @@
|
||||
#include <boost/container/list.hpp>
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/interprocess/allocators/cached_adaptive_pool.hpp>
|
||||
#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
|
||||
<int, managed_shared_memory::segment_manager>
|
||||
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
|
||||
<int, managed_shared_memory::segment_manager> priv_node_allocator_t;
|
||||
typedef ipcdetail::cached_adaptive_pool_v1
|
||||
<int, managed_shared_memory::segment_manager>
|
||||
cached_node_allocator_v1_t;
|
||||
<int, managed_shared_memory::segment_manager> 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<int, managed_shared_memory::segment_manager>;
|
||||
template class cached_adaptive_pool<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class cached_adaptive_pool<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
namespace ipcdetail {
|
||||
|
||||
template class ipcdetail::cached_adaptive_pool_v1<int, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::cached_adaptive_pool_v1<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::cached_adaptive_pool_v1<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
}}}
|
||||
|
||||
//Alias list types
|
||||
typedef boost::container::list<int, cached_node_allocator_t> MyShmList;
|
||||
typedef boost::container::list<int, cached_node_allocator_v1_t> MyShmListV1;
|
||||
typedef boost::container::list<int, priv_node_allocator_t> MyShmList;
|
||||
typedef boost::container::list<int, priv_node_allocator_v1_t> MyShmListV1;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_t> MyOShmList;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_v1_t> MyOShmListV1;
|
||||
|
||||
//Alias vector types
|
||||
typedef boost::container::vector<int, cached_node_allocator_t> MyShmVector;
|
||||
typedef boost::container::vector<int, cached_node_allocator_v1_t> MyShmVectorV1;
|
||||
typedef boost::container::vector<int, priv_node_allocator_t> MyShmVector;
|
||||
typedef boost::container::vector<int, priv_node_allocator_v1_t> MyShmVectorV1;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_t> MyOShmVector;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_v1_t> MyOShmVectorV1;
|
||||
|
||||
int main ()
|
||||
{
|
||||
if(test::list_test<managed_shared_memory, MyShmList, true>())
|
||||
if(test::list_test<managed_shared_memory, MyShmList, true>(false))
|
||||
return 1;
|
||||
if(test::list_test<managed_shared_memory, MyShmListV1, true>(false))
|
||||
return 1;
|
||||
|
||||
if(test::list_test<managed_shared_memory, MyShmListV1, true>())
|
||||
if(test::list_test<managed_shared_memory, MyOShmList, true>())
|
||||
return 1;
|
||||
if(test::list_test<managed_shared_memory, MyOShmListV1, true>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyShmVector>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVector>())
|
||||
return 1;
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,31 +12,37 @@
|
||||
#include <boost/container/list.hpp>
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/interprocess/allocators/private_adaptive_pool.hpp>
|
||||
#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
|
||||
<int, managed_shared_memory::segment_manager> priv_node_allocator_t;
|
||||
typedef ipcdetail::private_adaptive_pool_v1
|
||||
<int, managed_shared_memory::segment_manager> 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<int, managed_shared_memory::segment_manager>;
|
||||
template class private_adaptive_pool<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class private_adaptive_pool<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
namespace ipcdetail {
|
||||
|
||||
template class ipcdetail::private_adaptive_pool_v1<int, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::private_adaptive_pool_v1<oint_t, managed_shared_memory::segment_manager>;
|
||||
template class ipcdetail::private_adaptive_pool_v1<void, managed_shared_memory::segment_manager>;
|
||||
|
||||
}}}
|
||||
@@ -44,10 +50,14 @@ template class ipcdetail::private_adaptive_pool_v1<void, managed_shared_memory::
|
||||
//Alias list types
|
||||
typedef boost::container::list<int, priv_node_allocator_t> MyShmList;
|
||||
typedef boost::container::list<int, priv_node_allocator_v1_t> MyShmListV1;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_t> MyOShmList;
|
||||
typedef boost::container::list<oint_t, shmem_onode_allocator_v1_t> MyOShmListV1;
|
||||
|
||||
//Alias vector types
|
||||
typedef boost::container::vector<int, priv_node_allocator_t> MyShmVector;
|
||||
typedef boost::container::vector<int, priv_node_allocator_v1_t> MyShmVectorV1;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_t> MyOShmVector;
|
||||
typedef boost::container::vector<oint_t, shmem_onode_allocator_v1_t> MyOShmVectorV1;
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -55,9 +65,21 @@ int main ()
|
||||
return 1;
|
||||
if(test::list_test<managed_shared_memory, MyShmListV1, true>(false))
|
||||
return 1;
|
||||
|
||||
if(test::list_test<managed_shared_memory, MyOShmList, true>(false))
|
||||
return 1;
|
||||
if(test::list_test<managed_shared_memory, MyOShmListV1, true>(false))
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyShmVector>())
|
||||
return 1;
|
||||
if(test::vector_test<managed_shared_memory, MyShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVector>())
|
||||
return 1;
|
||||
if(test::vector_test<managed_shared_memory, MyOShmVectorV1>())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user