Remove outermost loop parameter.
[official-gcc/graphite-test-results.git] / libstdc++-v3 / src / bitmap_allocator.cc
blob55b308de25b404e004c71dcefe4a04618b050d30
1 // Bitmap Allocator. Out of line function definitions. -*- C++ -*-
3 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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)
30 namespace __detail
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);
46 size_t*
47 free_list::
48 _M_get(size_t __sz) throw(std::bad_alloc)
50 #if defined __GTHREADS
51 __mutex_type& __bfl_mutex = _M_get_mutex();
52 #endif
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
62 // implementation.
63 #if defined __GTHREADS
64 __bfl_mutex.unlock();
65 #endif
66 // Try twice to get the memory: once directly, and the 2nd
67 // time after clearing the free list. If both fail, then throw
68 // std::bad_alloc().
69 int __ctr = 2;
70 while (__ctr)
72 size_t* __ret = 0;
73 --__ctr;
74 __try
76 __ret = reinterpret_cast<size_t*>
77 (::operator new(__sz + sizeof(size_t)));
79 __catch(const std::bad_alloc&)
81 this->_M_clear();
83 if (!__ret)
84 continue;
85 *__ret = __sz;
86 return __ret + 1;
88 std::__throw_bad_alloc();
90 else
92 size_t* __ret = *__tmp;
93 _M_get_free_list().erase(__tmp);
94 #if defined __GTHREADS
95 __bfl_mutex.unlock();
96 #endif
97 return __ret + 1;
101 void
102 free_list::
103 _M_clear()
105 #if defined __GTHREADS
106 __gnu_cxx::__scoped_lock __bfl_lock(_M_get_mutex());
107 #endif
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);
113 ++__iter;
115 __free_list.clear();
118 // Instantiations.
119 template class bitmap_allocator<char>;
120 template class bitmap_allocator<wchar_t>;
122 _GLIBCXX_END_NAMESPACE