summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-14 17:52:18 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-14 17:52:18 +0000
commit731514a129505a2ddae8237fea894c19d8ba51cf (patch)
tree52fc656274dd3ad9a50d564dc1d9d813ec3ff42c /libstdc++-v3/src
parent97a18f01925451bc32c0e0f952840ae36099a647 (diff)
downloadgcc-731514a129505a2ddae8237fea894c19d8ba51cf.tar.gz
2004-10-14 Dhruv Matani <dhruvbird@gmx.net>
* ext/bitmap_allocator.h: Clean-up add/remove functions. * src/bitmap_allocator.cc: New file. Contains the out-of-line function definitions, static initialization of variables, and explicit instantiations needed for the allocator. * src/Makefile.am: Add. * src/Makefile.in: Regenerate. * config/linker.map.gnu: Add the necessary symbols. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89042 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/Makefile.am1
-rw-r--r--libstdc++-v3/src/Makefile.in17
-rw-r--r--libstdc++-v3/src/bitmap_allocator.cc133
3 files changed, 143 insertions, 8 deletions
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index fb393f2a957..b2ca5f6201d 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -96,6 +96,7 @@ basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC)
# Sources present in the src directory.
sources = \
+ bitmap_allocator.cc \
pool_allocator.cc \
mt_allocator.cc \
codecvt.cc \
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index ba9df3c4999..eb0b0c68f5a 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -64,14 +64,14 @@ am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \
ctype_members.lo messages_members.lo monetary_members.lo \
numeric_members.lo time_members.lo
am__objects_2 = basic_file.lo c++locale.lo
-am__objects_3 = pool_allocator.lo mt_allocator.lo codecvt.lo \
- complex_io.lo ctype.lo debug.lo debug_list.lo functexcept.lo \
- globals_locale.lo globals_io.lo ios.lo ios_failure.lo \
- ios_init.lo ios_locale.lo limits.lo list.lo locale.lo \
- locale_init.lo locale_facets.lo localename.lo stdexcept.lo \
- strstream.lo tree.lo allocator-inst.lo concept-inst.lo \
- fstream-inst.lo ext-inst.lo io-inst.lo istream-inst.lo \
- locale-inst.lo locale-misc-inst.lo misc-inst.lo \
+am__objects_3 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \
+ codecvt.lo complex_io.lo ctype.lo debug.lo debug_list.lo \
+ functexcept.lo globals_locale.lo globals_io.lo ios.lo \
+ ios_failure.lo ios_init.lo ios_locale.lo limits.lo list.lo \
+ locale.lo locale_init.lo locale_facets.lo localename.lo \
+ stdexcept.lo strstream.lo tree.lo allocator-inst.lo \
+ concept-inst.lo fstream-inst.lo ext-inst.lo io-inst.lo \
+ istream-inst.lo locale-inst.lo locale-misc-inst.lo misc-inst.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo $(am__objects_1) $(am__objects_2)
@@ -306,6 +306,7 @@ host_sources_extra = \
# Sources present in the src directory.
sources = \
+ bitmap_allocator.cc \
pool_allocator.cc \
mt_allocator.cc \
codecvt.cc \
diff --git a/libstdc++-v3/src/bitmap_allocator.cc b/libstdc++-v3/src/bitmap_allocator.cc
new file mode 100644
index 00000000000..f37c5dca28b
--- /dev/null
+++ b/libstdc++-v3/src/bitmap_allocator.cc
@@ -0,0 +1,133 @@
+// Bitmap Allocator. Out of line function definitions. -*- C++ -*-
+
+// Copyright (C) 2004 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#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<unsigned int*>;
+
+ template unsigned int** __lower_bound
+ (unsigned int**, unsigned int**,
+ unsigned int 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;
+
+ unsigned int*
+ free_list::
+ _M_get(unsigned int __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))
+ {
+ // We release the lock here, because operator new is
+ // guaranteed to be thread-safe by the underlying
+ // implementation.
+#if defined __GTHREADS
+ __bfl_lock._M_unlock();
+#endif
+ // Try twice to get the memory: once directly, and the 2nd
+ // time after clearing the free list. If both fail, then
+ // throw std::bad_alloc().
+ unsigned int __ctr = 2;
+ while (__ctr)
+ {
+ unsigned int* __ret = 0;
+ --__ctr;
+ try
+ {
+ __ret = reinterpret_cast<unsigned int*>
+ (::operator new(__sz + sizeof(unsigned int)));
+ }
+ catch(...)
+ {
+ this->_M_clear();
+ }
+ if (!__ret)
+ continue;
+ *__ret = __sz;
+ return reinterpret_cast<unsigned int*>
+ (reinterpret_cast<char*>(__ret) + sizeof(unsigned int));
+ }
+ throw std::bad_alloc();
+ }
+ else
+ {
+ unsigned int* __ret = *__temp;
+ _S_free_list.erase(__temp);
+#if defined __GTHREADS
+ __bfl_lock._M_unlock();
+#endif
+ return reinterpret_cast<unsigned int*>
+ (reinterpret_cast<char*>(__ret) + sizeof(unsigned int));
+ }
+ }
+
+ 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();
+ }
+
+ // Instantiations.
+ template class bitmap_allocator<char>;
+ template class bitmap_allocator<wchar_t>;
+} // namespace __gnu_cxx