Public Types | Public Member Functions | Private Member Functions | Private Attributes

TAO_Notify_Refcountable Class Reference

Thread-safe refounting, calls the <release> method when refcount falls to 0. More...

#include <Refcountable.h>

Inheritance diagram for TAO_Notify_Refcountable:
Inheritance graph
[legend]
Collaboration diagram for TAO_Notify_Refcountable:
Collaboration graph
[legend]

List of all members.

Public Types

typedef
TAO_Notify_Refcountable_Guard_T
< TAO_Notify_Refcountable
Ptr

Public Member Functions

 TAO_Notify_Refcountable (void)
 Constructor.
virtual ~TAO_Notify_Refcountable ()
CORBA::ULong _incr_refcnt (void)
CORBA::ULong _decr_refcnt (void)

Private Member Functions

virtual void release (void)=0
 The release method is called when the refcount reaches 0.

Private Attributes

ACE_Atomic_Op< TAO_SYNCH_MUTEX,
CORBA::Long
refcount_

Detailed Description

Thread-safe refounting, calls the <release> method when refcount falls to 0.

The refcount is initialized to 0. When an instance of a derived class becomes owned by a managed pointer (Refcountable_Guard_T) the reference count becomes non-zero.

Instances declared on the stack should always have a refcount of zero.

A method that creates or simply returns an instance of Refcountable should not increment the reference count. It is the responsibility of the client to increment the reference count (take ownership or guard against deletion). The client cannot know if the method will or will not incr the refcount on its behalf.

Use Refcountable_Guard_T or similar service to guarantee the exception safe direct pairing of increments and decrements. Avoid calling _incr_refcnt and _decr_refcnt.

Definition at line 60 of file Refcountable.h.


Member Typedef Documentation


Constructor & Destructor Documentation

TAO_Notify_Refcountable::TAO_Notify_Refcountable ( void   ) 

Constructor.

Definition at line 70 of file Refcountable.cpp.

{
}

TAO_Notify_Refcountable::~TAO_Notify_Refcountable (  )  [virtual]

Destructor public for stack allocated instances

Definition at line 74 of file Refcountable.cpp.

{
#if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
  TAO_Notify_Tracker::Entry e = TAO_Notify_Tracker::get_instance().find( this );
  if ( e.obj != 0 )
  {
    ACE_DEBUG ((LM_DEBUG,"object:%x %s(%d) with refcount:%d destroyed incorrectly.\n",
        e.obj, e.class_name, e.obj->ref_id_, e.obj->refcount_.value() ));
 
    if ( e.obj != this || e.obj->ref_id_ != this->ref_id_ )
    {
      ACE_DEBUG ((LM_DEBUG, "  with an ID mismatch %x->%d != %x->%d!\n",
        this, ref_id_, e.obj, e.obj->ref_id_));
    }
    TAO_Notify_Tracker::get_instance().remove( this );
  }
#endif
  CORBA::ULong refcount = this->refcount_.value();
  ACE_ASSERT( refcount == 0 );
  ACE_UNUSED_ARG(refcount);
}


Member Function Documentation

CORBA::ULong TAO_Notify_Refcountable::_decr_refcnt ( void   ) 

Definition at line 118 of file Refcountable.cpp.

{
  CORBA::Long refcount = --this->refcount_;

  if (TAO_debug_level > 1 )
  {
    ACE_DEBUG ((LM_DEBUG,"object:%x decr refcount = %d\n", this, refcount ));
  }

  ACE_ASSERT(refcount >= 0);

  if (refcount == 0)
  {
    #if ( USE_TAO_NOTIFY_TRACKER != 0 )
      TAO_Notify_Tracker::get_instance().remove( this );
    #endif
    this->release ();
  }
  return refcount;
}

CORBA::ULong TAO_Notify_Refcountable::_incr_refcnt ( void   ) 

This method sigantures deliberately match the RefCounting methods required for ESF Proxy Public for bridge implementations and various guard classes

Definition at line 98 of file Refcountable.cpp.

{
  CORBA::Long refcount = ++this->refcount_;
  if (TAO_debug_level > 1 )
  {
    ACE_DEBUG ((LM_DEBUG,"object:%x incr refcount = %d\n", this, refcount ));
  }
#if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
  // Stack-instantiated-non-servants should never have _incr_refcnt called.
  // We do not care about stack-instances. Stack-instantiated servants break
  // the tracker.
  if ( refcount == 1 )
  {
    TAO_Notify_Tracker::get_instance().add( this );
  }
#endif
  return refcount;
}

virtual void TAO_Notify_Refcountable::release ( void   )  [private, pure virtual]

The release method is called when the refcount reaches 0.

Implemented in TAO_Notify_Event_Manager, TAO_Notify_Reactive_Task, TAO_Notify_Timer_Queue, and TAO_Notify_Timer_Reactor.


Member Data Documentation

Use a signed counter so that we can more easily detect boundary conditions such as too many _decr_refcnt() calls.

Definition at line 87 of file Refcountable.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines