Commit a8155711 by Dhruv Matani Committed by Paolo Carlini

bitmap_allocator.h: Change unsigned int -> size_t...

2004-10-17  Dhruv Matani  <dhruvbird@gmx.net>
	    Paolo Carlini  <pcarlini@suse.de>

	* include/ext/bitmap_allocator.h: Change unsigned int -> size_t: this
	makes the code 64-bit correct and also fixes (together with using at
	the beginning a bitmap 2 * size_t bytes wide) alignment issues: now
	8 is guaranteed, easily tunable to 16 via _BALLOC_ALIGN_BYTES.
	Fix pthread-rope7.cc fail by nulling out __mini_vector<> destructor.
	* src/bitmap_allocator.cc: Change to size_t.
	* config/linker-map.gnu: Adjust.

Co-Authored-By: Paolo Carlini <pcarlini@suse.de>

From-SVN: r89170
parent 05dfb0b0
2004-10-17 Dhruv Matani <dhruvbird@gmx.net>
Paolo Carlini <pcarlini@suse.de>
* include/ext/bitmap_allocator.h: Change unsigned int -> size_t: this
makes the code 64-bit correct and also fixes (together with using at
the beginning a bitmap 2 * size_t bytes wide) alignment issues: now
8 is guaranteed, easily tunable to 16 via _BALLOC_ALIGN_BYTES.
Fix pthread-rope7.cc fail by nulling out __mini_vector<> destructor.
* src/bitmap_allocator.cc: Change to size_t.
* config/linker-map.gnu: Adjust.
2004-10-16 Benjamin Kosnik <bkoz@redhat.com> 2004-10-16 Benjamin Kosnik <bkoz@redhat.com>
* include/tr1/array: Don't use layout_type. * include/tr1/array: Don't use layout_type.
......
...@@ -273,7 +273,7 @@ GLIBCXX_3.4.3 { ...@@ -273,7 +273,7 @@ GLIBCXX_3.4.3 {
_ZN9__gnu_cxx9free_list12_S_free_listE; _ZN9__gnu_cxx9free_list12_S_free_listE;
_ZN9__gnu_cxx9free_list12_S_bfl_mutexE; _ZN9__gnu_cxx9free_list12_S_bfl_mutexE;
_ZN9__gnu_cxx9free_list6_M_getEj; _ZN9__gnu_cxx9free_list6_M_getE*;
_ZN9__gnu_cxx9free_list8_M_clearEv; _ZN9__gnu_cxx9free_list8_M_clearEv;
# stub functions from libmath # stub functions from libmath
......
...@@ -54,6 +54,10 @@ ...@@ -54,6 +54,10 @@
// itself(to debug the allocator itself). // itself(to debug the allocator itself).
//#define _BALLOC_SANITY_CHECK //#define _BALLOC_SANITY_CHECK
// The constant in the expression below is the alignment required in
// bytes.
#define _BALLOC_ALIGN_BYTES 8
#if defined _BALLOC_SANITY_CHECK #if defined _BALLOC_SANITY_CHECK
#include <cassert> #include <cassert>
#define _BALLOC_ASSERT(_EXPR) assert(_EXPR) #define _BALLOC_ASSERT(_EXPR) assert(_EXPR)
...@@ -238,6 +242,7 @@ namespace __gnu_cxx ...@@ -238,6 +242,7 @@ namespace __gnu_cxx
_M_end_of_storage(0) _M_end_of_storage(0)
{ } { }
#if 0
~__mini_vector() ~__mini_vector()
{ {
if (this->_M_start) if (this->_M_start)
...@@ -246,6 +251,7 @@ namespace __gnu_cxx ...@@ -246,6 +251,7 @@ namespace __gnu_cxx
- this->_M_start); - this->_M_start);
} }
} }
#endif
size_type size_type
size() const throw() size() const throw()
...@@ -370,7 +376,7 @@ namespace __gnu_cxx ...@@ -370,7 +376,7 @@ namespace __gnu_cxx
enum enum
{ {
bits_per_byte = 8, bits_per_byte = 8,
bits_per_block = sizeof(unsigned int) * bits_per_byte bits_per_block = sizeof(size_t) * bits_per_byte
}; };
template<typename _ForwardIterator, typename _Tp, typename _Compare> template<typename _ForwardIterator, typename _Tp, typename _Compare>
...@@ -419,7 +425,7 @@ namespace __gnu_cxx ...@@ -419,7 +425,7 @@ namespace __gnu_cxx
{ return (__ap.second - __ap.first) + 1; } { return (__ap.second - __ap.first) + 1; }
template<typename _AddrPair> template<typename _AddrPair>
inline size_t inline size_t
__num_bitmaps(_AddrPair __ap) __num_bitmaps(_AddrPair __ap)
{ return __num_blocks(__ap) / bits_per_block; } { return __num_blocks(__ap) / bits_per_block; }
...@@ -477,8 +483,8 @@ namespace __gnu_cxx ...@@ -477,8 +483,8 @@ namespace __gnu_cxx
typedef typename balloc::__mini_vector<_Block_pair> _BPVector; typedef typename balloc::__mini_vector<_Block_pair> _BPVector;
typedef typename _BPVector::difference_type _Counter_type; typedef typename _BPVector::difference_type _Counter_type;
unsigned int* _M_pbitmap; size_t* _M_pbitmap;
unsigned int _M_data_offset; _Counter_type _M_data_offset;
public: public:
_Ffit_finder() : _M_pbitmap(0), _M_data_offset(0) _Ffit_finder() : _M_pbitmap(0), _M_data_offset(0)
...@@ -487,10 +493,11 @@ namespace __gnu_cxx ...@@ -487,10 +493,11 @@ namespace __gnu_cxx
bool bool
operator()(_Block_pair __bp) throw() operator()(_Block_pair __bp) throw()
{ {
// Set the _rover to the last unsigned integer, which is the // Set the _rover to the last physical location bitmap,
// bitmap to the first free block. Thus, the bitmaps are in exact // which is the bitmap which belongs to the first free
// reverse order of the actual memory layout. So, we count down // block. Thus, the bitmaps are in exact reverse order of
// the bimaps, which is the same as moving up the memory. // the actual memory layout. So, we count down the bimaps,
// which is the same as moving up the memory.
// If the used count stored at the start of the Bit Map headers // If the used count stored at the start of the Bit Map headers
// is equal to the number of Objects that the current Block can // is equal to the number of Objects that the current Block can
...@@ -499,13 +506,12 @@ namespace __gnu_cxx ...@@ -499,13 +506,12 @@ namespace __gnu_cxx
_Counter_type __diff = _Counter_type __diff =
__gnu_cxx::balloc::__num_bitmaps(__bp); __gnu_cxx::balloc::__num_bitmaps(__bp);
if (*reinterpret_cast<unsigned int*> if (*(reinterpret_cast<size_t*>
(reinterpret_cast<char*>(__bp.first) - (sizeof(unsigned int) * (__bp.first) - (__diff + 1))
(__diff+1)))
== __gnu_cxx::balloc::__num_blocks(__bp)) == __gnu_cxx::balloc::__num_blocks(__bp))
return false; return false;
unsigned int* __rover = reinterpret_cast<unsigned int*>(__bp.first) - 1; size_t* __rover = reinterpret_cast<size_t*>(__bp.first) - 1;
for (_Counter_type __i = 0; __i < __diff; ++__i) for (_Counter_type __i = 0; __i < __diff; ++__i)
{ {
...@@ -521,11 +527,11 @@ namespace __gnu_cxx ...@@ -521,11 +527,11 @@ namespace __gnu_cxx
} }
unsigned int* size_t*
_M_get() const throw() _M_get() const throw()
{ return _M_pbitmap; } { return _M_pbitmap; }
unsigned int _Counter_type
_M_offset() const throw() _M_offset() const throw()
{ return _M_data_offset * bits_per_block; } { return _M_data_offset * bits_per_block; }
}; };
...@@ -542,19 +548,19 @@ namespace __gnu_cxx ...@@ -542,19 +548,19 @@ namespace __gnu_cxx
typedef _Tp pointer; typedef _Tp pointer;
_BPVector& _M_vbp; _BPVector& _M_vbp;
unsigned int* _M_curr_bmap; size_t* _M_curr_bmap;
unsigned int* _M_last_bmap_in_block; size_t* _M_last_bmap_in_block;
_Index_type _M_curr_index; _Index_type _M_curr_index;
public: public:
// Use the 2nd parameter with care. Make sure that such an // Use the 2nd parameter with care. Make sure that such an
// entry exists in the vector before passing that particular // entry exists in the vector before passing that particular
// index to this ctor. // index to this ctor.
_Bitmap_counter(_BPVector& Rvbp, int __index = -1) : _M_vbp(Rvbp) _Bitmap_counter(_BPVector& Rvbp, long __index = -1) : _M_vbp(Rvbp)
{ this->_M_reset(__index); } { this->_M_reset(__index); }
void void
_M_reset(int __index = -1) throw() _M_reset(long __index = -1) throw()
{ {
if (__index == -1) if (__index == -1)
{ {
...@@ -564,10 +570,10 @@ namespace __gnu_cxx ...@@ -564,10 +570,10 @@ namespace __gnu_cxx
} }
_M_curr_index = __index; _M_curr_index = __index;
_M_curr_bmap = reinterpret_cast<unsigned int*> _M_curr_bmap = reinterpret_cast<size_t*>
(_M_vbp[_M_curr_index].first) - 1; (_M_vbp[_M_curr_index].first) - 1;
_BALLOC_ASSERT(__index <= (int)_M_vbp.size() - 1); _BALLOC_ASSERT(__index <= (long)_M_vbp.size() - 1);
_M_last_bmap_in_block = _M_curr_bmap _M_last_bmap_in_block = _M_curr_bmap
- ((_M_vbp[_M_curr_index].second - ((_M_vbp[_M_curr_index].second
...@@ -579,7 +585,7 @@ namespace __gnu_cxx ...@@ -579,7 +585,7 @@ namespace __gnu_cxx
// function ONLY those values that are known to be correct, // function ONLY those values that are known to be correct,
// otherwise this will mess up big time. // otherwise this will mess up big time.
void void
_M_set_internal_bitmap(unsigned int* __new_internal_marker) throw() _M_set_internal_bitmap(size_t* __new_internal_marker) throw()
{ _M_curr_bmap = __new_internal_marker; } { _M_curr_bmap = __new_internal_marker; }
bool bool
...@@ -601,7 +607,7 @@ namespace __gnu_cxx ...@@ -601,7 +607,7 @@ namespace __gnu_cxx
return *this; return *this;
} }
unsigned int* size_t*
_M_get() const throw() _M_get() const throw()
{ return _M_curr_bmap; } { return _M_curr_bmap; }
...@@ -609,50 +615,51 @@ namespace __gnu_cxx ...@@ -609,50 +615,51 @@ namespace __gnu_cxx
_M_base() const throw() _M_base() const throw()
{ return _M_vbp[_M_curr_index].first; } { return _M_vbp[_M_curr_index].first; }
unsigned int _Index_type
_M_offset() const throw() _M_offset() const throw()
{ {
return bits_per_block return bits_per_block
* ((reinterpret_cast<unsigned int*>(this->_M_base()) * ((reinterpret_cast<size_t*>(this->_M_base())
- _M_curr_bmap) - 1); - _M_curr_bmap) - 1);
} }
unsigned int _Index_type
_M_where() const throw() _M_where() const throw()
{ return _M_curr_index; } { return _M_curr_index; }
}; };
inline void inline void
__bit_allocate(unsigned int* __pbmap, unsigned int __pos) throw() __bit_allocate(size_t* __pbmap, size_t __pos) throw()
{ {
unsigned int __mask = 1 << __pos; size_t __mask = 1 << __pos;
__mask = ~__mask; __mask = ~__mask;
*__pbmap &= __mask; *__pbmap &= __mask;
} }
inline void inline void
__bit_free(unsigned int* __pbmap, unsigned int __pos) throw() __bit_free(size_t* __pbmap, size_t __pos) throw()
{ {
unsigned int __mask = 1 << __pos; size_t __mask = 1 << __pos;
*__pbmap |= __mask; *__pbmap |= __mask;
} }
} // namespace balloc } // namespace balloc
// Generic Version of the bsf instruction. // Generic Version of the bsf instruction.
inline unsigned int inline size_t
_Bit_scan_forward(register unsigned int __num) _Bit_scan_forward(size_t __num)
{ return static_cast<unsigned int>(__builtin_ctz(__num)); } { return static_cast<size_t>(__builtin_ctzl(__num)); }
class free_list class free_list
{ {
typedef unsigned int* value_type; typedef size_t* value_type;
typedef balloc::__mini_vector<value_type> vector_type; typedef balloc::__mini_vector<value_type> vector_type;
typedef vector_type::iterator iterator; typedef vector_type::iterator iterator;
struct _LT_pointer_compare struct _LT_pointer_compare
{ {
bool bool
operator()(const unsigned int* __pui, const unsigned int __cui) const throw() operator()(const size_t* __pui,
const size_t __cui) const throw()
{ return *__pui < __cui; } { return *__pui < __cui; }
}; };
...@@ -662,9 +669,9 @@ namespace __gnu_cxx ...@@ -662,9 +669,9 @@ namespace __gnu_cxx
static vector_type _S_free_list; static vector_type _S_free_list;
void void
_M_validate(unsigned int* __addr) throw() _M_validate(size_t* __addr) throw()
{ {
const unsigned int __max_size = 64; const vector_type::size_type __max_size = 64;
if (_S_free_list.size() >= __max_size) if (_S_free_list.size() >= __max_size)
{ {
// Ok, the threshold value has been reached. We determine // Ok, the threshold value has been reached. We determine
...@@ -696,10 +703,10 @@ namespace __gnu_cxx ...@@ -696,10 +703,10 @@ namespace __gnu_cxx
} }
bool bool
_M_should_i_give(unsigned int __block_size, _M_should_i_give(size_t __block_size,
unsigned int __required_size) throw() size_t __required_size) throw()
{ {
const unsigned int __max_wastage_percentage = 36; const size_t __max_wastage_percentage = 36;
if (__block_size >= __required_size && if (__block_size >= __required_size &&
(((__block_size - __required_size) * 100 / __block_size) (((__block_size - __required_size) * 100 / __block_size)
< __max_wastage_percentage)) < __max_wastage_percentage))
...@@ -710,20 +717,19 @@ namespace __gnu_cxx ...@@ -710,20 +717,19 @@ namespace __gnu_cxx
public: public:
inline void inline void
_M_insert(unsigned int* __addr) throw() _M_insert(size_t* __addr) throw()
{ {
#if defined __GTHREADS #if defined __GTHREADS
_Auto_Lock __bfl_lock(&_S_bfl_mutex); _Auto_Lock __bfl_lock(&_S_bfl_mutex);
#endif #endif
// Call _M_validate to decide what should be done with // Call _M_validate to decide what should be done with
// this particular free list. // this particular free list.
this->_M_validate(reinterpret_cast<unsigned int*> this->_M_validate(reinterpret_cast<size_t*>(__addr) - 1);
(reinterpret_cast<char*>(__addr) // See discussion as to why this is 1!
- sizeof(unsigned int)));
} }
unsigned int* size_t*
_M_get(unsigned int __sz) throw(std::bad_alloc); _M_get(size_t __sz) throw(std::bad_alloc);
// This function just clears the internal Free List, and gives back // This function just clears the internal Free List, and gives back
// all the memory to the OS. // all the memory to the OS.
...@@ -771,7 +777,7 @@ namespace __gnu_cxx ...@@ -771,7 +777,7 @@ namespace __gnu_cxx
}; };
private: private:
template<unsigned int _BSize, unsigned int _AlignSize> template<size_t _BSize, size_t _AlignSize>
struct aligned_size struct aligned_size
{ {
enum enum
...@@ -783,7 +789,8 @@ namespace __gnu_cxx ...@@ -783,7 +789,8 @@ namespace __gnu_cxx
struct _Alloc_block struct _Alloc_block
{ {
char __M_unused[aligned_size<sizeof(value_type), 8>::value]; char __M_unused[aligned_size<sizeof(value_type),
_BALLOC_ALIGN_BYTES>::value];
}; };
...@@ -824,17 +831,16 @@ namespace __gnu_cxx ...@@ -824,17 +831,16 @@ namespace __gnu_cxx
_S_check_for_free_blocks(); _S_check_for_free_blocks();
#endif #endif
const unsigned int __num_bitmaps = _S_block_size / balloc::bits_per_block; const size_t __num_bitmaps = _S_block_size / balloc::bits_per_block;
const unsigned int __size_to_allocate = sizeof(unsigned int) const size_t __size_to_allocate = sizeof(size_t)
+ _S_block_size * sizeof(_Alloc_block) + _S_block_size * sizeof(_Alloc_block)
+ __num_bitmaps * sizeof(unsigned int); + __num_bitmaps * sizeof(size_t);
unsigned int* __temp = size_t* __temp =
reinterpret_cast<unsigned int*>(this->_M_get(__size_to_allocate)); reinterpret_cast<size_t*>
(this->_M_get(__size_to_allocate));
*__temp = 0; *__temp = 0;
// ++__temp; ++__temp;
__temp = reinterpret_cast<unsigned int*>
(reinterpret_cast<char*>(__temp) + sizeof(unsigned int));
// The Header information goes at the Beginning of the Block. // The Header information goes at the Beginning of the Block.
_Block_pair __bp = _Block_pair __bp =
...@@ -847,10 +853,10 @@ namespace __gnu_cxx ...@@ -847,10 +853,10 @@ namespace __gnu_cxx
// Fill the Vector with this information. // Fill the Vector with this information.
_S_mem_blocks.push_back(__bp); _S_mem_blocks.push_back(__bp);
unsigned int __bit_mask = 0; // 0 Indicates all Allocated. size_t __bit_mask = 0; // 0 Indicates all Allocated.
__bit_mask = ~__bit_mask; // 1 Indicates all Free. __bit_mask = ~__bit_mask; // 1 Indicates all Free.
for (unsigned int __i = 0; __i < __num_bitmaps; ++__i) for (size_t __i = 0; __i < __num_bitmaps; ++__i)
__temp[__i] = __bit_mask; __temp[__i] = __bit_mask;
_S_block_size *= 2; _S_block_size *= 2;
...@@ -858,7 +864,7 @@ namespace __gnu_cxx ...@@ -858,7 +864,7 @@ namespace __gnu_cxx
static _BPVector _S_mem_blocks; static _BPVector _S_mem_blocks;
static unsigned int _S_block_size; static size_t _S_block_size;
static __gnu_cxx::balloc:: static __gnu_cxx::balloc::
_Bitmap_counter<_Alloc_block*> _S_last_request; _Bitmap_counter<_Alloc_block*> _S_last_request;
static typename _BPVector::size_type _S_last_dealloc_index; static typename _BPVector::size_type _S_last_dealloc_index;
...@@ -918,7 +924,7 @@ namespace __gnu_cxx ...@@ -918,7 +924,7 @@ namespace __gnu_cxx
// Search was successful. Ok, now mark the first bit from // Search was successful. Ok, now mark the first bit from
// the right as 0, meaning Allocated. This bit is obtained // the right as 0, meaning Allocated. This bit is obtained
// by calling _M_get() on __fff. // by calling _M_get() on __fff.
unsigned int __nz_bit = _Bit_scan_forward(*__fff._M_get()); size_t __nz_bit = _Bit_scan_forward(*__fff._M_get());
balloc::__bit_allocate(__fff._M_get(), __nz_bit); balloc::__bit_allocate(__fff._M_get(), __nz_bit);
_S_last_request._M_reset(__bpi - _S_mem_blocks.begin()); _S_last_request._M_reset(__bpi - _S_mem_blocks.begin());
...@@ -926,10 +932,10 @@ namespace __gnu_cxx ...@@ -926,10 +932,10 @@ namespace __gnu_cxx
// Now, get the address of the bit we marked as allocated. // Now, get the address of the bit we marked as allocated.
pointer __ret = reinterpret_cast<pointer> pointer __ret = reinterpret_cast<pointer>
(__bpi->first + __fff._M_offset() + __nz_bit); (__bpi->first + __fff._M_offset() + __nz_bit);
unsigned int* __puse_count = reinterpret_cast<unsigned int*> size_t* __puse_count =
(reinterpret_cast<char*> reinterpret_cast<size_t*>
(__bpi->first) - (sizeof(unsigned int) * (__bpi->first)
(__gnu_cxx::balloc::__num_bitmaps(*__bpi)+1))); - (__gnu_cxx::balloc::__num_bitmaps(*__bpi) + 1);
++(*__puse_count); ++(*__puse_count);
return __ret; return __ret;
...@@ -950,18 +956,16 @@ namespace __gnu_cxx ...@@ -950,18 +956,16 @@ namespace __gnu_cxx
// _S_last_request holds a pointer to a valid bit map, that // _S_last_request holds a pointer to a valid bit map, that
// points to a free block in memory. // points to a free block in memory.
unsigned int __nz_bit = _Bit_scan_forward(*_S_last_request._M_get()); size_t __nz_bit = _Bit_scan_forward(*_S_last_request._M_get());
balloc::__bit_allocate(_S_last_request._M_get(), __nz_bit); balloc::__bit_allocate(_S_last_request._M_get(), __nz_bit);
pointer __ret = reinterpret_cast<pointer> pointer __ret = reinterpret_cast<pointer>
(_S_last_request._M_base() + _S_last_request._M_offset() + __nz_bit); (_S_last_request._M_base() + _S_last_request._M_offset() + __nz_bit);
unsigned int* __puse_count = reinterpret_cast<unsigned int*> size_t* __puse_count = reinterpret_cast<size_t*>
(reinterpret_cast<char*> (_S_mem_blocks[_S_last_request._M_where()].first)
(_S_mem_blocks[_S_last_request._M_where()].first) - (__gnu_cxx::balloc::
- (sizeof(unsigned int) * __num_bitmaps(_S_mem_blocks[_S_last_request._M_where()]) + 1);
(__gnu_cxx::balloc::
__num_bitmaps(_S_mem_blocks[_S_last_request._M_where()])+1)));
++(*__puse_count); ++(*__puse_count);
return __ret; return __ret;
...@@ -982,7 +986,7 @@ namespace __gnu_cxx ...@@ -982,7 +986,7 @@ namespace __gnu_cxx
typedef typename _BPVector::difference_type _Difference_type; typedef typename _BPVector::difference_type _Difference_type;
_Difference_type __diff; _Difference_type __diff;
int __displacement; long __displacement;
_BALLOC_ASSERT(_S_last_dealloc_index >= 0); _BALLOC_ASSERT(_S_last_dealloc_index >= 0);
...@@ -1000,10 +1004,12 @@ namespace __gnu_cxx ...@@ -1000,10 +1004,12 @@ namespace __gnu_cxx
else else
{ {
_Iterator _iter = _Iterator _iter =
__gnu_cxx::balloc::__find_if(_S_mem_blocks.begin(), __gnu_cxx::balloc::
_S_mem_blocks.end(), __find_if(_S_mem_blocks.begin(),
__gnu_cxx::balloc:: _S_mem_blocks.end(),
_Inclusive_between<_Alloc_block*>(__real_p)); __gnu_cxx::balloc::
_Inclusive_between<_Alloc_block*>(__real_p));
_BALLOC_ASSERT(_iter != _S_mem_blocks.end()); _BALLOC_ASSERT(_iter != _S_mem_blocks.end());
__diff = _iter - _S_mem_blocks.begin(); __diff = _iter - _S_mem_blocks.begin();
...@@ -1012,17 +1018,16 @@ namespace __gnu_cxx ...@@ -1012,17 +1018,16 @@ namespace __gnu_cxx
} }
// Get the position of the iterator that has been found. // Get the position of the iterator that has been found.
const unsigned int __rotate = __displacement % balloc::bits_per_block; const size_t __rotate = __displacement % balloc::bits_per_block;
unsigned int* __bitmapC = size_t* __bitmapC =
reinterpret_cast<unsigned int*>(_S_mem_blocks[__diff].first) - 1; reinterpret_cast<size_t*>
(_S_mem_blocks[__diff].first) - 1;
__bitmapC -= (__displacement / balloc::bits_per_block); __bitmapC -= (__displacement / balloc::bits_per_block);
balloc::__bit_free(__bitmapC, __rotate); balloc::__bit_free(__bitmapC, __rotate);
unsigned int* __puse_count = reinterpret_cast<unsigned int*> size_t* __puse_count = reinterpret_cast<size_t*>
(reinterpret_cast<char*> (_S_mem_blocks[__diff].first)
(_S_mem_blocks[__diff].first) - (__gnu_cxx::balloc::__num_bitmaps(_S_mem_blocks[__diff]) + 1);
- (sizeof(unsigned int) *
(__gnu_cxx::balloc::__num_bitmaps(_S_mem_blocks[__diff])+1)));
_BALLOC_ASSERT(*__puse_count != 0); _BALLOC_ASSERT(*__puse_count != 0);
...@@ -1143,7 +1148,8 @@ namespace __gnu_cxx ...@@ -1143,7 +1148,8 @@ namespace __gnu_cxx
bitmap_allocator<_Tp>::_S_mem_blocks; bitmap_allocator<_Tp>::_S_mem_blocks;
template<typename _Tp> template<typename _Tp>
unsigned int bitmap_allocator<_Tp>::_S_block_size = balloc::bits_per_block; size_t bitmap_allocator<_Tp>::_S_block_size =
2 * balloc::bits_per_block;
template<typename _Tp> template<typename _Tp>
typename __gnu_cxx::bitmap_allocator<_Tp>::_BPVector::size_type typename __gnu_cxx::bitmap_allocator<_Tp>::_BPVector::size_type
......
...@@ -41,11 +41,11 @@ namespace __gnu_cxx ...@@ -41,11 +41,11 @@ namespace __gnu_cxx
<bitmap_allocator<wchar_t>::_Alloc_block*, <bitmap_allocator<wchar_t>::_Alloc_block*,
bitmap_allocator<wchar_t>::_Alloc_block*> >; bitmap_allocator<wchar_t>::_Alloc_block*> >;
template class __mini_vector<unsigned int*>; template class __mini_vector<size_t*>;
template unsigned int** __lower_bound template size_t** __lower_bound
(unsigned int**, unsigned int**, (size_t**, size_t**,
unsigned int const&, free_list::_LT_pointer_compare); size_t const&, free_list::_LT_pointer_compare);
} }
#if defined __GTHREADS #if defined __GTHREADS
...@@ -53,9 +53,9 @@ namespace __gnu_cxx ...@@ -53,9 +53,9 @@ namespace __gnu_cxx
#endif #endif
free_list::vector_type free_list::_S_free_list; free_list::vector_type free_list::_S_free_list;
unsigned int* size_t*
free_list:: free_list::
_M_get(unsigned int __sz) throw(std::bad_alloc) _M_get(size_t __sz) throw(std::bad_alloc)
{ {
#if defined __GTHREADS #if defined __GTHREADS
_Lock __bfl_lock(&_S_bfl_mutex); _Lock __bfl_lock(&_S_bfl_mutex);
...@@ -77,15 +77,15 @@ namespace __gnu_cxx ...@@ -77,15 +77,15 @@ namespace __gnu_cxx
// Try twice to get the memory: once directly, and the 2nd // Try twice to get the memory: once directly, and the 2nd
// time after clearing the free list. If both fail, then // time after clearing the free list. If both fail, then
// throw std::bad_alloc(). // throw std::bad_alloc().
unsigned int __ctr = 2; int __ctr = 2;
while (__ctr) while (__ctr)
{ {
unsigned int* __ret = 0; size_t* __ret = 0;
--__ctr; --__ctr;
try try
{ {
__ret = reinterpret_cast<unsigned int*> __ret = reinterpret_cast<size_t*>
(::operator new(__sz + sizeof(unsigned int))); (::operator new(__sz + sizeof(size_t)));
} }
catch(...) catch(...)
{ {
...@@ -94,20 +94,18 @@ namespace __gnu_cxx ...@@ -94,20 +94,18 @@ namespace __gnu_cxx
if (!__ret) if (!__ret)
continue; continue;
*__ret = __sz; *__ret = __sz;
return reinterpret_cast<unsigned int*> return __ret + 1;
(reinterpret_cast<char*>(__ret) + sizeof(unsigned int));
} }
throw std::bad_alloc(); throw std::bad_alloc();
} }
else else
{ {
unsigned int* __ret = *__temp; size_t* __ret = *__temp;
_S_free_list.erase(__temp); _S_free_list.erase(__temp);
#if defined __GTHREADS #if defined __GTHREADS
__bfl_lock._M_unlock(); __bfl_lock._M_unlock();
#endif #endif
return reinterpret_cast<unsigned int*> return __ret + 1;
(reinterpret_cast<char*>(__ret) + sizeof(unsigned int));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment