diff options
Diffstat (limited to 'libstdc++-v3/include/ext/bitmap_allocator.h')
-rw-r--r-- | libstdc++-v3/include/ext/bitmap_allocator.h | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/libstdc++-v3/include/ext/bitmap_allocator.h b/libstdc++-v3/include/ext/bitmap_allocator.h index 9f02065046f..f607709e8f9 100644 --- a/libstdc++-v3/include/ext/bitmap_allocator.h +++ b/libstdc++-v3/include/ext/bitmap_allocator.h @@ -1,6 +1,6 @@ // Bitmap Allocator. -*- C++ -*- -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -717,10 +717,21 @@ namespace __gnu_cxx { return *__pui < __cui; } }; -#if defined __GTHREADS - static _Mutex _S_bfl_mutex; +#if defined __GTHREADS + _Mutex* + _M_get_mutex() + { + static _Mutex _S_mutex; + return &_S_mutex; + } #endif - static vector_type _S_free_list; + + vector_type& + _M_get_free_list() + { + static vector_type _S_free_list; + return _S_free_list; + } /** @brief Performs validation of memory based on their size. * @@ -735,12 +746,13 @@ namespace __gnu_cxx void _M_validate(size_t* __addr) throw() { + vector_type& __free_list = _M_get_free_list(); const vector_type::size_type __max_size = 64; - if (_S_free_list.size() >= __max_size) + if (__free_list.size() >= __max_size) { // Ok, the threshold value has been reached. We determine // which block to remove from the list of free blocks. - if (*__addr >= *_S_free_list.back()) + if (*__addr >= *__free_list.back()) { // Ok, the new block is greater than or equal to the // last block in the list of free blocks. We just free @@ -752,18 +764,18 @@ namespace __gnu_cxx { // Deallocate the last block in the list of free lists, // and insert the new one in it's correct position. - ::operator delete(static_cast<void*>(_S_free_list.back())); - _S_free_list.pop_back(); + ::operator delete(static_cast<void*>(__free_list.back())); + __free_list.pop_back(); } } // Just add the block to the list of free lists unconditionally. iterator __temp = __gnu_cxx::balloc::__lower_bound - (_S_free_list.begin(), _S_free_list.end(), + (__free_list.begin(), __free_list.end(), *__addr, _LT_pointer_compare()); // We may insert the new free list before _temp; - _S_free_list.insert(__temp, __addr); + __free_list.insert(__temp, __addr); } /** @brief Decides whether the wastage of memory is acceptable for @@ -801,7 +813,7 @@ namespace __gnu_cxx _M_insert(size_t* __addr) throw() { #if defined __GTHREADS - _Auto_Lock __bfl_lock(&_S_bfl_mutex); + _Auto_Lock __bfl_lock(_M_get_mutex()); #endif // Call _M_validate to decide what should be done with // this particular free list. |