]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/container for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP | |
12 | #define BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP | |
13 | ||
14 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | ||
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
22 | #include <boost/container/detail/config_begin.hpp> | |
23 | #include <boost/container/detail/workaround.hpp> | |
24 | #include <boost/container/throw_exception.hpp> | |
25 | ||
26 | #include <boost/intrusive/slist.hpp> | |
27 | #include <boost/container/detail/pool_common.hpp> | |
28 | #include <boost/container/detail/dlmalloc.hpp> | |
29 | #include <cstddef> | |
30 | ||
31 | namespace boost{ | |
32 | namespace container{ | |
33 | namespace container_detail{ | |
34 | ||
35 | struct node_slist_helper | |
36 | : public boost::container::container_detail::node_slist<void*> | |
37 | {}; | |
38 | ||
39 | struct fake_segment_manager | |
40 | { | |
41 | typedef void * void_pointer; | |
42 | static const std::size_t PayloadPerAllocation = BOOST_CONTAINER_ALLOCATION_PAYLOAD; | |
43 | ||
44 | typedef boost::container::container_detail:: | |
45 | basic_multiallocation_chain<void*> multiallocation_chain; | |
46 | static void deallocate(void_pointer p) | |
47 | { dlmalloc_free(p); } | |
48 | ||
49 | static void deallocate_many(multiallocation_chain &chain) | |
50 | { | |
51 | std::size_t size = chain.size(); | |
52 | std::pair<void*, void*> ptrs = chain.extract_data(); | |
53 | dlmalloc_memchain dlchain; | |
54 | BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&dlchain, ptrs.first, ptrs.second, size); | |
55 | dlmalloc_multidealloc(&dlchain); | |
56 | } | |
57 | ||
58 | typedef std::ptrdiff_t difference_type; | |
59 | typedef std::size_t size_type; | |
60 | ||
61 | static void *allocate_aligned(std::size_t nbytes, std::size_t alignment) | |
62 | { | |
63 | void *ret = dlmalloc_memalign(nbytes, alignment); | |
64 | if(!ret) | |
65 | boost::container::throw_bad_alloc(); | |
66 | return ret; | |
67 | } | |
68 | ||
69 | static void *allocate(std::size_t nbytes) | |
70 | { | |
71 | void *ret = dlmalloc_malloc(nbytes); | |
72 | if(!ret) | |
73 | boost::container::throw_bad_alloc(); | |
74 | return ret; | |
75 | } | |
76 | }; | |
77 | ||
78 | } //namespace boost{ | |
79 | } //namespace container{ | |
80 | } //namespace container_detail{ | |
81 | ||
82 | namespace boost { | |
83 | namespace container { | |
84 | namespace container_detail { | |
85 | ||
86 | template<class T> | |
87 | struct is_stateless_segment_manager; | |
88 | ||
89 | template<> | |
90 | struct is_stateless_segment_manager | |
91 | <boost::container::container_detail::fake_segment_manager> | |
92 | { | |
93 | static const bool value = true; | |
94 | }; | |
95 | ||
96 | } //namespace container_detail { | |
97 | } //namespace container { | |
98 | } //namespace boost { | |
99 | ||
100 | #include <boost/container/detail/config_end.hpp> | |
101 | ||
102 | #endif //BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP |