X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=libstdc%2B%2B-v3%2Fsrc%2Fallocator.cc;h=af5de4d2cb9ede279f5b07bfd35798a90dbbc9bc;hp=d4928735848d29d7a333f9fb90fd85b6abfcb2c0;hb=c3bf0cd64a6eeb7966c91dd8ec91dc6079906439;hpb=194381673f6b23b351917c26c3f1830de8e1d9f8 diff --git a/libstdc++-v3/src/allocator.cc b/libstdc++-v3/src/allocator.cc index d4928735848..af5de4d2cb9 100644 --- a/libstdc++-v3/src/allocator.cc +++ b/libstdc++-v3/src/allocator.cc @@ -36,20 +36,25 @@ #include #include -namespace __gnu_cxx +namespace __gnu_internal { - // Instantiations for __mt_alloc. - template class __mt_alloc; - template class __mt_alloc; + __glibcxx_mutex_define_initialized(palloc_init_mutex); +} - // Definitions and instantiations for __pool_alloc and base class. +namespace __gnu_cxx +{ + // Definitions for __pool_alloc_base. __pool_base::_Obj* volatile* __pool_base::_M_get_free_list(size_t __bytes) { size_t __i = ((__bytes + (size_t)_S_align - 1) / (size_t)_S_align - 1); - return _S_free_list + __i - 1; + return _S_free_list + __i; } + __gthread_mutex_t& + __pool_base::_M_get_mutex() + { return __gnu_internal::palloc_init_mutex; } + // Allocate memory in large chunks in order to avoid fragmenting the // heap too much. Assume that __n is properly aligned. We hold the // allocation lock. @@ -89,21 +94,17 @@ namespace __gnu_cxx _S_start_free = static_cast(::operator new(__bytes_to_get)); if (_S_start_free == 0) { - size_t __i; - _Obj* volatile* __free_list; - _Obj* __p; - // Try to make do with what we have. That can't hurt. We // do not try smaller requests, since that tends to result // in disaster on multi-process machines. - __i = __n; + size_t __i = __n; for (; __i <= (size_t) _S_max_bytes; __i += (size_t) _S_align) { - __free_list = _M_get_free_list(__i); - __p = *__free_list; + _Obj* volatile* __free_list = _M_get_free_list(__i); + _Obj* __p = *__free_list; if (__p != 0) { - *__free_list = __p -> _M_free_list_link; + *__free_list = __p->_M_free_list_link; _S_start_free = (char*)__p; _S_end_free = _S_start_free + __i; return _M_allocate_chunk(__n, __nobjs); @@ -112,9 +113,10 @@ namespace __gnu_cxx } } _S_end_free = 0; // In case of exception. - _S_start_free = static_cast(::operator new(__bytes_to_get)); + // This should either throw an exception or remedy the situation. // Thus we assume it succeeded. + _S_start_free = static_cast(::operator new(__bytes_to_get)); } _S_heap_size += __bytes_to_get; _S_end_free = _S_start_free + __bytes_to_get; @@ -134,26 +136,25 @@ namespace __gnu_cxx _Obj* __result; _Obj* __current_obj; _Obj* __next_obj; - int __i; - if (1 == __nobjs) + if (__nobjs == 1) return __chunk; __free_list = _M_get_free_list(__n); // Build free list in chunk. __result = (_Obj*)(void*)__chunk; *__free_list = __next_obj = (_Obj*)(void*)(__chunk + __n); - for (__i = 1; ; __i++) + for (int __i = 1; ; __i++) { __current_obj = __next_obj; __next_obj = (_Obj*)(void*)((char*)__next_obj + __n); if (__nobjs - 1 == __i) { - __current_obj -> _M_free_list_link = 0; + __current_obj->_M_free_list_link = 0; break; } else - __current_obj -> _M_free_list_link = __next_obj; + __current_obj->_M_free_list_link = __next_obj; } return __result; } @@ -165,9 +166,4 @@ namespace __gnu_cxx char* __pool_base::_S_end_free = 0; size_t __pool_base::_S_heap_size = 0; - - _STL_mutex_lock __pool_base::_Lock::_S_lock __STL_MUTEX_INITIALIZER; - - template class __pool_alloc; - template class __pool_alloc; } // namespace __gnu_cxx