/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program 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: http://www.gnu.org/licenses/gpl.txt.

   This program 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.
*/

#ifndef _POLYMAKE_STD_CPP_ALLOCATOR_H
#define _POLYMAKE_STD_CPP_ALLOCATOR_H "$Project: polymake $$Id: c++allocator.h,v 1.6 2004/09/20 15:14:11 gawrilow Exp $"

/* This file is a wrapper for gcc >= 3.4
   Earlier versions and como are served by stl_alloc.h
*/
#include <ext/pool_allocator.h>

namespace std {
   template <typename T> class allocator;
}

#if __GNUC_PATCHLEVEL__ == 1 && !defined(POLY_MT)
namespace __gnu_cxx {
   template <> inline __gnu_cxx::__pool_base<true>::_Lock::_Lock() { }
   template <> inline __gnu_cxx::__pool_base<true>::_Lock::~_Lock() { }
}
#endif // __GNUC_PATCHLEVEL__ == 1

namespace pm {
#if __GNUC_PATCHLEVEL__ == 0
#ifdef POLY_MT
   typedef __gnu_cxx::__pool_alloc<true,0> raw_alloc;
#else
   typedef __gnu_cxx::__pool_alloc<false,0> raw_alloc;
#endif

   template <typename T>
   class base_raw_allocator : public raw_alloc {
   public:
      static
      T* allocate(size_t n)
      {
	 return __builtin_expect(n==0,0) ? 0 : reinterpret_cast<T*>(raw_alloc::allocate(n*sizeof(T)));
      }
   };
#else // __GNUC_PATCHLEVEL__ >= 1
   struct raw_alloc {
      typedef __gnu_cxx::__pool_alloc<char> Alloc;

      static
      void* allocate(size_t n)
      {
	 return Alloc().allocate(n);
      }

      static
      void deallocate(void* p, size_t n)
      {
	 Alloc().deallocate((char*)p,n);
      }
   };
#endif // __GNUC_PATCHLEVEL__ >= 1

   void* reallocate(void*, size_t, size_t);
}

#if __GNUC_PATCHLEVEL__==0
#  define ___glibcxx_base_allocator pm::base_raw_allocator
#else
#  define ___glibcxx_base_allocator __gnu_cxx::__pool_alloc
#endif

#define _POLYMAKE_LACKING_REALLOCATE

#endif // _POLYMAKE_STD_CPP_ALLOCATOR_H

// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
