#ifndef BOOST_CONTAINER_DETAIL_NODE_POOL_HPP
#define BOOST_CONTAINER_DETAIL_NODE_POOL_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
#include <boost/container/detail/mutex.hpp>
#include <boost/container/detail/pool_common_alloc.hpp>
#include <boost/container/detail/node_pool_impl.hpp>
#include <boost/container/detail/mutex.hpp>
#include <boost/move/utility_core.hpp>
#include <cstddef>
#include <cassert>
namespace boost {
namespace container {
namespace dtl {
template< std::size_t NodeSize, std::size_t NodesPerBlock >
class private_node_pool
: public boost::container::dtl::
private_node_pool_impl<fake_segment_manager>
{
typedef boost::container::dtl::
private_node_pool_impl<fake_segment_manager> base_t;
private_node_pool(const private_node_pool &);
private_node_pool &operator=(const private_node_pool &);
public:
typedef typename base_t::multiallocation_chain multiallocation_chain;
BOOST_STATIC_CONSTEXPR std::size_t nodes_per_block = NodesPerBlock;
private_node_pool()
: base_t(0, NodeSize, NodesPerBlock)
{}
};
template< std::size_t NodeSize
, std::size_t NodesPerBlock
>
class shared_node_pool
: public private_node_pool<NodeSize, NodesPerBlock>
{
private:
typedef private_node_pool<NodeSize, NodesPerBlock> private_node_allocator_t;
public:
typedef typename private_node_allocator_t::free_nodes_t free_nodes_t;
typedef typename private_node_allocator_t::multiallocation_chain multiallocation_chain;
shared_node_pool()
: private_node_allocator_t(){}
~shared_node_pool()
{}
void *allocate_node()
{
scoped_lock<default_mutex> guard(mutex_);
return private_node_allocator_t::allocate_node();
}
void deallocate_node(void *ptr)
{
scoped_lock<default_mutex> guard(mutex_);
private_node_allocator_t::deallocate_node(ptr);
}
void allocate_nodes(const std::size_t n, multiallocation_chain &chain)
{
scoped_lock<default_mutex> guard(mutex_);
return private_node_allocator_t::allocate_nodes(n, chain);
}
void deallocate_nodes(multiallocation_chain &chain)
{
scoped_lock<default_mutex> guard(mutex_);
private_node_allocator_t::deallocate_nodes(chain);
}
void deallocate_free_blocks()
{
scoped_lock<default_mutex> guard(mutex_);
private_node_allocator_t::deallocate_free_blocks();
}
void purge_blocks()
{
scoped_lock<default_mutex> guard(mutex_);
private_node_allocator_t::purge_blocks();
}
std::size_t num_free_nodes()
{
scoped_lock<default_mutex> guard(mutex_);
return private_node_allocator_t::num_free_nodes();
}
private:
default_mutex mutex_;
};
} } }
#include <boost/container/detail/config_end.hpp>
#endif