bitmap_allocator.cc [plain text]
#include <ext/bitmap_allocator.h>
namespace __gnu_cxx
{
namespace balloc
{
template class __mini_vector<std::pair
<bitmap_allocator<char>::_Alloc_block*,
bitmap_allocator<char>::_Alloc_block*> >;
template class __mini_vector<std::pair
<bitmap_allocator<wchar_t>::_Alloc_block*,
bitmap_allocator<wchar_t>::_Alloc_block*> >;
template class __mini_vector<size_t*>;
template size_t** __lower_bound
(size_t**, size_t**,
size_t const&, free_list::_LT_pointer_compare);
}
#if defined __GTHREADS
_Mutex free_list::_S_bfl_mutex;
#endif
free_list::vector_type free_list::_S_free_list;
size_t*
free_list::
_M_get(size_t __sz) throw(std::bad_alloc)
{
#if defined __GTHREADS
_Lock __bfl_lock(&_S_bfl_mutex);
__bfl_lock._M_lock();
#endif
iterator __temp =
__gnu_cxx::balloc::__lower_bound
(_S_free_list.begin(), _S_free_list.end(),
__sz, _LT_pointer_compare());
if (__temp == _S_free_list.end() || !_M_should_i_give(**__temp, __sz))
{
#if defined __GTHREADS
__bfl_lock._M_unlock();
#endif
int __ctr = 2;
while (__ctr)
{
size_t* __ret = 0;
--__ctr;
try
{
__ret = reinterpret_cast<size_t*>
(::operator new(__sz + sizeof(size_t)));
}
catch(...)
{
this->_M_clear();
}
if (!__ret)
continue;
*__ret = __sz;
return __ret + 1;
}
throw std::bad_alloc();
}
else
{
size_t* __ret = *__temp;
_S_free_list.erase(__temp);
#if defined __GTHREADS
__bfl_lock._M_unlock();
#endif
return __ret + 1;
}
}
void
free_list::
_M_clear()
{
#if defined __GTHREADS
_Auto_Lock __bfl_lock(&_S_bfl_mutex);
#endif
iterator __iter = _S_free_list.begin();
while (__iter != _S_free_list.end())
{
::operator delete((void*)*__iter);
++__iter;
}
_S_free_list.clear();
}
template class bitmap_allocator<char>;
template class bitmap_allocator<wchar_t>;
}