1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/pool/singleton_pool.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +// Copyright (C) 2000, 2001 Stephen Cleary
1.5 +//
1.6 +// Distributed under the Boost Software License, Version 1.0. (See
1.7 +// accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +//
1.10 +// See http://www.boost.org for updates, documentation, and revision history.
1.11 +
1.12 +#ifndef BOOST_SINGLETON_POOL_HPP
1.13 +#define BOOST_SINGLETON_POOL_HPP
1.14 +
1.15 +#include <boost/pool/poolfwd.hpp>
1.16 +
1.17 +// boost::pool
1.18 +#include <boost/pool/pool.hpp>
1.19 +// boost::details::pool::singleton_default
1.20 +#include <boost/pool/detail/singleton.hpp>
1.21 +// boost::details::pool::guard
1.22 +#include <boost/pool/detail/guard.hpp>
1.23 +
1.24 +namespace boost {
1.25 +
1.26 +//
1.27 +// The singleton_pool class allows other pool interfaces for types of the same
1.28 +// size to share the same pool
1.29 +//
1.30 +template <typename Tag, unsigned RequestedSize,
1.31 + typename UserAllocator,
1.32 + typename Mutex,
1.33 + unsigned NextSize>
1.34 +struct singleton_pool
1.35 +{
1.36 + public:
1.37 + typedef Tag tag;
1.38 + typedef Mutex mutex;
1.39 + typedef UserAllocator user_allocator;
1.40 + typedef typename pool<UserAllocator>::size_type size_type;
1.41 + typedef typename pool<UserAllocator>::difference_type difference_type;
1.42 +
1.43 + BOOST_STATIC_CONSTANT(unsigned, requested_size = RequestedSize);
1.44 + BOOST_STATIC_CONSTANT(unsigned, next_size = NextSize);
1.45 +
1.46 + private:
1.47 + struct pool_type: Mutex
1.48 + {
1.49 + pool<UserAllocator> p;
1.50 + pool_type():p(RequestedSize, NextSize) { }
1.51 + };
1.52 +
1.53 + typedef details::pool::singleton_default<pool_type> singleton;
1.54 +
1.55 + singleton_pool();
1.56 +
1.57 + public:
1.58 + static void * malloc()
1.59 + {
1.60 + pool_type & p = singleton::instance();
1.61 + details::pool::guard<Mutex> g(p);
1.62 + return p.p.malloc();
1.63 + }
1.64 + static void * ordered_malloc()
1.65 + {
1.66 + pool_type & p = singleton::instance();
1.67 + details::pool::guard<Mutex> g(p);
1.68 + return p.p.ordered_malloc();
1.69 + }
1.70 + static void * ordered_malloc(const size_type n)
1.71 + {
1.72 + pool_type & p = singleton::instance();
1.73 + details::pool::guard<Mutex> g(p);
1.74 + return p.p.ordered_malloc(n);
1.75 + }
1.76 + static bool is_from(void * const ptr)
1.77 + {
1.78 + pool_type & p = singleton::instance();
1.79 + details::pool::guard<Mutex> g(p);
1.80 + return p.p.is_from(ptr);
1.81 + }
1.82 + static void free(void * const ptr)
1.83 + {
1.84 + pool_type & p = singleton::instance();
1.85 + details::pool::guard<Mutex> g(p);
1.86 + p.p.free(ptr);
1.87 + }
1.88 + static void ordered_free(void * const ptr)
1.89 + {
1.90 + pool_type & p = singleton::instance();
1.91 + details::pool::guard<Mutex> g(p);
1.92 + p.p.ordered_free(ptr);
1.93 + }
1.94 + static void free(void * const ptr, const size_type n)
1.95 + {
1.96 + pool_type & p = singleton::instance();
1.97 + details::pool::guard<Mutex> g(p);
1.98 + p.p.free(ptr, n);
1.99 + }
1.100 + static void ordered_free(void * const ptr, const size_type n)
1.101 + {
1.102 + pool_type & p = singleton::instance();
1.103 + details::pool::guard<Mutex> g(p);
1.104 + p.p.ordered_free(ptr, n);
1.105 + }
1.106 + static bool release_memory()
1.107 + {
1.108 + pool_type & p = singleton::instance();
1.109 + details::pool::guard<Mutex> g(p);
1.110 + return p.p.release_memory();
1.111 + }
1.112 + static bool purge_memory()
1.113 + {
1.114 + pool_type & p = singleton::instance();
1.115 + details::pool::guard<Mutex> g(p);
1.116 + return p.p.purge_memory();
1.117 + }
1.118 +};
1.119 +
1.120 +} // namespace boost
1.121 +
1.122 +#endif