1 // Bitmap Allocator. Out of line function definitions. -*- C++ -*-
3 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 #include <ext/bitmap_allocator.h>
28 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
32 template class __mini_vector<
33 std::pair<bitmap_allocator<char>::_Alloc_block*,
34 bitmap_allocator<char>::_Alloc_block*> >;
36 template class __mini_vector<
37 std::pair<bitmap_allocator<wchar_t>::_Alloc_block*,
38 bitmap_allocator<wchar_t>::_Alloc_block*> >;
40 template class __mini_vector<size_t*>;
42 template size_t** __lower_bound(size_t**, size_t**, size_t const&,
43 free_list::_LT_pointer_compare);
48 _M_get(size_t __sz) throw(std::bad_alloc)
50 #if defined __GTHREADS
51 __mutex_type& __bfl_mutex = _M_get_mutex();
53 const vector_type& __free_list = _M_get_free_list();
54 using __gnu_cxx::__detail::__lower_bound;
55 iterator __tmp = __lower_bound(__free_list.begin(), __free_list.end(),
56 __sz, _LT_pointer_compare());
58 if (__tmp == __free_list.end() || !_M_should_i_give(**__tmp, __sz))
60 // We release the lock here, because operator new is
61 // guaranteed to be thread-safe by the underlying
63 #if defined __GTHREADS
66 // Try twice to get the memory: once directly, and the 2nd
67 // time after clearing the free list. If both fail, then throw
76 __ret = reinterpret_cast<size_t*>
77 (::operator new(__sz + sizeof(size_t)));
88 std::__throw_bad_alloc();
92 size_t* __ret = *__tmp;
93 _M_get_free_list().erase(__tmp);
94 #if defined __GTHREADS
105 #if defined __GTHREADS
106 __gnu_cxx::__scoped_lock __bfl_lock(_M_get_mutex());
108 vector_type& __free_list = _M_get_free_list();
109 iterator __iter = __free_list.begin();
110 while (__iter != __free_list.end())
112 ::operator delete((void*)*__iter);
119 template class bitmap_allocator<char>;
120 template class bitmap_allocator<wchar_t>;
122 _GLIBCXX_END_NAMESPACE