TAO_Notify_Refcountable Class Reference

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

#include <Refcountable.h>

Inheritance diagram for TAO_Notify_Refcountable:

Inheritance 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 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

typedef TAO_Notify_Refcountable_Guard_T< TAO_Notify_Refcountable > TAO_Notify_Refcountable::Ptr
 

Reimplemented in TAO_Notify_ConsumerAdmin, TAO_Notify_Event, TAO_Notify_Event_Manager, TAO_Notify_EventChannel, TAO_Notify_EventChannelFactory, TAO_Notify_Proxy, TAO_Notify_ProxyConsumer, TAO_Notify_ProxySupplier, TAO_Notify_SupplierAdmin, TAO_Notify_Timer, TAO_Notify_Timer_Queue, TAO_Notify_Timer_Reactor, and TAO_Notify_Worker_Task.

Definition at line 63 of file Refcountable.h.


Constructor & Destructor Documentation

TAO_Notify_Refcountable::TAO_Notify_Refcountable void   ) 
 

Constructor.

Definition at line 70 of file Refcountable.cpp.

00071 {
00072 }

TAO_Notify_Refcountable::~TAO_Notify_Refcountable  )  [virtual]
 

Destructor public for stack allocated instances

Definition at line 74 of file Refcountable.cpp.

References ACE_ASSERT, ACE_DEBUG, and LM_DEBUG.

00075 {
00076 #if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
00077   TAO_Notify_Tracker::Entry e = TAO_Notify_Tracker::get_instance().find( this );
00078   if ( e.obj != 0 )
00079   {
00080     ACE_DEBUG ((LM_DEBUG,"object:%x %s(%d) with refcount:%d destroyed incorrectly.\n",
00081         e.obj, e.class_name, e.obj->ref_id_, e.obj->refcount_.value() ));
00082  
00083     if ( e.obj != this || e.obj->ref_id_ != this->ref_id_ )
00084     {
00085       ACE_DEBUG ((LM_DEBUG, "  with an ID mismatch %x->%d != %x->%d!\n",
00086         this, ref_id_, e.obj, e.obj->ref_id_));
00087     }
00088     TAO_Notify_Tracker::get_instance().remove( this );
00089   }
00090 #endif
00091   CORBA::ULong refcount = this->refcount_.value();
00092   ACE_ASSERT( refcount == 0 );
00093   ACE_UNUSED_ARG(refcount);
00094 }


Member Function Documentation

CORBA::ULong TAO_Notify_Refcountable::_decr_refcnt void   ) 
 

Definition at line 118 of file Refcountable.cpp.

References ACE_ASSERT, ACE_DEBUG, LM_DEBUG, release(), and TAO_debug_level.

Referenced by TAO_Notify_Peer::_decr_refcnt(), TAO_Notify_SupplierAdmin::_remove_ref(), TAO_Notify_Proxy_T< SERVANT_TYPE >::_remove_ref(), TAO_Notify_EventChannelFactory::_remove_ref(), TAO_Notify_EventChannel::_remove_ref(), TAO_Notify_ConsumerAdmin::_remove_ref(), TAO_Notify_ThreadPool_Task::close(), and TAO_Notify_ThreadPool_Task::init().

00119 {
00120   CORBA::Long refcount = --this->refcount_;
00121 
00122   if (TAO_debug_level > 1 )
00123   {
00124     ACE_DEBUG ((LM_DEBUG,"object:%x decr refcount = %d\n", this, refcount ));
00125   }
00126 
00127   ACE_ASSERT(refcount >= 0);
00128 
00129   if (refcount == 0)
00130   {
00131     #if ( USE_TAO_NOTIFY_TRACKER != 0 )
00132       TAO_Notify_Tracker::get_instance().remove( this );
00133     #endif
00134     this->release ();
00135   }
00136   return refcount;
00137 }

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.

References ACE_DEBUG, LM_DEBUG, and TAO_debug_level.

Referenced by TAO_Notify_SupplierAdmin::_add_ref(), TAO_Notify_Proxy_T< SERVANT_TYPE >::_add_ref(), TAO_Notify_EventChannelFactory::_add_ref(), TAO_Notify_EventChannel::_add_ref(), TAO_Notify_ConsumerAdmin::_add_ref(), TAO_Notify_Peer::_incr_refcnt(), TAO_Notify_ThreadPool_Task::init(), and TAO_Notify_Proxy_T< SERVANT_TYPE >::TAO_Notify_Proxy_T().

00099 {
00100   CORBA::Long refcount = ++this->refcount_;
00101   if (TAO_debug_level > 1 )
00102   {
00103     ACE_DEBUG ((LM_DEBUG,"object:%x incr refcount = %d\n", this, refcount ));
00104   }
00105 #if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
00106   // Stack-instantiated-non-servants should never have _incr_refcnt called.
00107   // We do not care about stack-instances. Stack-instantiated servants break
00108   // the tracker.
00109   if ( refcount == 1 )
00110   {
00111     TAO_Notify_Tracker::get_instance().add( this );
00112   }
00113 #endif
00114   return refcount;
00115 }

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

The release method is called when the refcount reaches 0.

Implemented in TAO_Notify_ConsumerAdmin, TAO_Notify_Event, TAO_Notify_Event_Manager, TAO_Notify_EventChannel, TAO_Notify_EventChannelFactory, TAO_Notify_EventTypeSeq, TAO_Notify_FilterAdmin, TAO_Notify_Reactive_Task, TAO_Notify::Reconnection_Registry, TAO_Notify_SupplierAdmin, TAO_Notify_ThreadPool_Task, TAO_Notify_Timer_Queue, TAO_Notify_Timer_Reactor, TAO_Notify_CosEC_ProxyPushConsumer, TAO_Notify_CosEC_ProxyPushSupplier, TAO_Notify_ProxyPushConsumer, TAO_Notify_ProxyPushSupplier, TAO_Notify_SequenceProxyPushConsumer, TAO_Notify_SequenceProxyPushSupplier, TAO_Notify_StructuredProxyPushConsumer, and TAO_Notify_StructuredProxyPushSupplier.

Referenced by _decr_refcnt().


Member Data Documentation

ACE_Atomic_Op<TAO_SYNCH_MUTEX, CORBA::Long> TAO_Notify_Refcountable::refcount_ [private]
 

Definition at line 87 of file Refcountable.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:33:01 2006 for TAO_CosNotification by doxygen 1.3.6