Poster of Linux kernelThe best gift for a Linux geek
ReferenceCounter

ReferenceCounter

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

ReferenceCounter -  

SYNOPSIS


#include <reference_counter.h>

Inherited by ReferenceCountedObject< T >, ReferenceCountedObject< DiffSolver >, ReferenceCountedObject< DofMap >, ReferenceCountedObject< DofObject >, ReferenceCountedObject< EigenSolver< Number > >, ReferenceCountedObject< EigenSolver< T > >, ReferenceCountedObject< Elem >, ReferenceCountedObject< FEBase >, ReferenceCountedObject< LinearSolver< Number > >, ReferenceCountedObject< LinearSolver< T > >, ReferenceCountedObject< Node >, ReferenceCountedObject< NonlinearSolver< Number > >, ReferenceCountedObject< NonlinearSolver< T > >, ReferenceCountedObject< NumericVector< Number > >, ReferenceCountedObject< NumericVector< T > >, ReferenceCountedObject< PointLocatorBase >, ReferenceCountedObject< Preconditioner< Number > >, ReferenceCountedObject< Preconditioner< T > >, ReferenceCountedObject< QBase >, ReferenceCountedObject< ShellMatrix< Number > >, ReferenceCountedObject< ShellMatrix< T > >, ReferenceCountedObject< Solver >, ReferenceCountedObject< SparseMatrix< Number > >, ReferenceCountedObject< SparseMatrix< T > >, ReferenceCountedObject< System >, ReferenceCountedObject< TimeSolver >, ReferenceCountedObject< TreeBase >, and ReferenceCountedObject< Value >.  

Public Member Functions


virtual ~ReferenceCounter ()
 

Static Public Member Functions


static std::string get_info ()

static void print_info ()

static unsigned int n_objects ()
 

Protected Types


typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions


ReferenceCounter ()

void increment_constructor_count (const std::string &name)

void increment_destructor_count (const std::string &name)
 

Static Protected Attributes


static Counts _counts

static Threads::atomic< unsigned int > _n_objects

static Threads::spin_mutex _mutex
 

Detailed Description

This is the base class for enabling reference counting. It should not be used by the user, thus it has a private constructor.

Author:

Benjamin S. Kirk, 2002-2007

Definition at line 44 of file reference_counter.h.  

Member Typedef Documentation

 

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected]Data structure to log the information. The log is identified by the class name.

Definition at line 105 of file reference_counter.h.  

Constructor & Destructor Documentation

 

ReferenceCounter::ReferenceCounter () [inline, protected]Constructor. Protected so that you cannont instantiate a ReferenceCounter, only derive from it.

Definition at line 130 of file reference_counter.h.

References _n_objects.

{
  _n_objects++;
}
 

ReferenceCounter::~ReferenceCounter () [inline, virtual]Destructor.

Definition at line 137 of file reference_counter.h.

References _n_objects.

{
  _n_objects--;
}
 

Member Function Documentation

 

std::string ReferenceCounter::get_info () [static]Gets a string containing the reference information.

Definition at line 45 of file reference_counter.C.

References _counts, and Quality::name().

Referenced by print_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)

  std::ostringstream out;
  
  out << '
      << ' ---------------------------------------------------------------------------- 
      << '| Reference count information                                                |
      << ' ---------------------------------------------------------------------------- ;
  
  for (Counts::iterator it = _counts.begin();
       it != _counts.end(); ++it)
    {
      const std::string name(it->first);
      const unsigned int creations    = it->second.first;
      const unsigned int destructions = it->second.second;

      out << '| ' << name << ' reference count information:
          << '|  Creations:    ' << creations    << '
          << '|  Destructions: ' << destructions << ';
    }
  
  out << ' ---------------------------------------------------------------------------- ;

  return out.str();

#else

  return '';
  
#endif
}
 

void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

Definition at line 149 of file reference_counter.h.

References _counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.first++;
}
 

void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

Definition at line 167 of file reference_counter.h.

References _counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.second++;
}
 

static unsigned int ReferenceCounter::n_objects () [inline, static]Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 76 of file reference_counter.h.

References _n_objects.

Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().

  { return _n_objects; }
 

void ReferenceCounter::print_info () [static]Prints the reference information to std::cout.

Definition at line 83 of file reference_counter.C.

References get_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
  
  std::cout << ReferenceCounter::get_info();
  
#endif
}
 

Member Data Documentation

 

ReferenceCounter::Counts ReferenceCounter::_counts [static, protected]Actually holds the data.

Definition at line 110 of file reference_counter.h.

Referenced by get_info(), increment_constructor_count(), and increment_destructor_count().  

Threads::spin_mutex ReferenceCounter::_mutex [static, protected]Mutual exclusion object to enable thread-safe reference counting.

Definition at line 123 of file reference_counter.h.  

Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected]The number of objects. Print the reference count information when the number returns to 0.

Definition at line 118 of file reference_counter.h.

Referenced by n_objects(), ReferenceCounter(), and ~ReferenceCounter().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Static Public Member Functions
Protected Types
Protected Member Functions
Static Protected Attributes
Detailed Description
Member Typedef Documentation
typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected]Data structure to log the information. The log is identified by the class name.
Constructor & Destructor Documentation
ReferenceCounter::ReferenceCounter () [inline, protected]Constructor. Protected so that you cannont instantiate a ReferenceCounter, only derive from it.
ReferenceCounter::~ReferenceCounter () [inline, virtual]Destructor.
Member Function Documentation
std::string ReferenceCounter::get_info () [static]Gets a string containing the reference information.
void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.
void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.
static unsigned int ReferenceCounter::n_objects () [inline, static]Prints the number of outstanding (created, but not yet destroyed) objects.
void ReferenceCounter::print_info () [static]Prints the reference information to std::cout.
Member Data Documentation
ReferenceCounter::Counts ReferenceCounter::_counts [static, protected]Actually holds the data.
Threads::spin_mutex ReferenceCounter::_mutex [static, protected]Mutual exclusion object to enable thread-safe reference counting.
Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected]The number of objects. Print the reference count information when the number returns to 0.
Author

This document was created by man2html, using the manual pages.
Time: 21:53:59 GMT, April 16, 2011