Update contrib.
1 // Copyright (C) 2000, 2001 Stephen Cleary
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org for updates, documentation, and revision history.
9 #ifndef BOOST_SINGLETON_POOL_HPP
10 #define BOOST_SINGLETON_POOL_HPP
12 #include <boost/pool/poolfwd.hpp>
15 #include <boost/pool/pool.hpp>
16 // boost::details::pool::singleton_default
17 #include <boost/pool/detail/singleton.hpp>
18 // boost::details::pool::guard
19 #include <boost/pool/detail/guard.hpp>
24 // The singleton_pool class allows other pool interfaces for types of the same
25 // size to share the same pool
27 template <typename Tag, unsigned RequestedSize,
28 typename UserAllocator,
36 typedef UserAllocator user_allocator;
37 typedef typename pool<UserAllocator>::size_type size_type;
38 typedef typename pool<UserAllocator>::difference_type difference_type;
40 BOOST_STATIC_CONSTANT(unsigned, requested_size = RequestedSize);
41 BOOST_STATIC_CONSTANT(unsigned, next_size = NextSize);
44 struct pool_type: Mutex
46 pool<UserAllocator> p;
47 pool_type():p(RequestedSize, NextSize) { }
50 typedef details::pool::singleton_default<pool_type> singleton;
55 static void * malloc()
57 pool_type & p = singleton::instance();
58 details::pool::guard<Mutex> g(p);
61 static void * ordered_malloc()
63 pool_type & p = singleton::instance();
64 details::pool::guard<Mutex> g(p);
65 return p.p.ordered_malloc();
67 static void * ordered_malloc(const size_type n)
69 pool_type & p = singleton::instance();
70 details::pool::guard<Mutex> g(p);
71 return p.p.ordered_malloc(n);
73 static bool is_from(void * const ptr)
75 pool_type & p = singleton::instance();
76 details::pool::guard<Mutex> g(p);
77 return p.p.is_from(ptr);
79 static void free(void * const ptr)
81 pool_type & p = singleton::instance();
82 details::pool::guard<Mutex> g(p);
85 static void ordered_free(void * const ptr)
87 pool_type & p = singleton::instance();
88 details::pool::guard<Mutex> g(p);
89 p.p.ordered_free(ptr);
91 static void free(void * const ptr, const size_type n)
93 pool_type & p = singleton::instance();
94 details::pool::guard<Mutex> g(p);
97 static void ordered_free(void * const ptr, const size_type n)
99 pool_type & p = singleton::instance();
100 details::pool::guard<Mutex> g(p);
101 p.p.ordered_free(ptr, n);
103 static bool release_memory()
105 pool_type & p = singleton::instance();
106 details::pool::guard<Mutex> g(p);
107 return p.p.release_memory();
109 static bool purge_memory()
111 pool_type & p = singleton::instance();
112 details::pool::guard<Mutex> g(p);
113 return p.p.purge_memory();