Ticket #4960: singleton_pool.hpp.patch

File singleton_pool.hpp.patch, 1.9 KB (added by Steven Watanabe, 12 years ago)

Patch adding instrumentation to singleton_pool

  • boost/pool/singleton_pool.hpp

     
    1818// boost::details::pool::guard
    1919#include <boost/pool/detail/guard.hpp>
    2020
     21#include <boost/units/detail/utility.hpp>
     22#include <iostream>
     23#include <set>
     24
    2125namespace boost {
    2226
     27inline int get_id() {
     28    static int result = 0;
     29    return result++;
     30}
     31
    2332//
    2433// The singleton_pool class allows other pool interfaces for types of the same
    2534//   size to share the same pool
     
    6473      details::pool::guard<Mutex> g(p);
    6574      return p.p.ordered_malloc();
    6675    }
     76    static int id() { static int result = get_id(); return result; }
    6777    static void * ordered_malloc(const size_type n)
    6878    {
    6979      pool_type & p = singleton::instance();
    7080      details::pool::guard<Mutex> g(p);
    71       return p.p.ordered_malloc(n);
     81     
     82      static bool is_typedefed = false;
     83      if(!is_typedefed) {
     84          is_typedefed = true;
     85          std::cout << "typedef " << boost::units::detail::demangle(typeid(singleton_pool).name())
     86              << "pool_type" << id() << ";\n";
     87      }
     88      std::cout << "tmp = pool_type" << id() << "::ordered_malloc(" << n << ");" << std::endl;
     89      void* result = p.p.ordered_malloc(n);
     90      static std::set<void*> known;
     91      if(known.insert(result).second) {
     92          std::cout << "void* ";
     93      }
     94      std::cout << "p" << result << " = tmp;\n";
     95      return result;
    7296    }
    7397    static bool is_from(void * const ptr)
    7498    {
     
    98122    {
    99123      pool_type & p = singleton::instance();
    100124      details::pool::guard<Mutex> g(p);
     125      std::cout << "pool_type" << id() << "::ordered_free(p" << ptr << ", " << n << ");" << std::endl;
    101126      p.p.ordered_free(ptr, n);
    102127    }
    103128    static bool release_memory()