TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, > Class Template Reference

TAO_ESF_Copy_On_Write. More...

#include <ESF_Copy_On_Write.h>

Inheritance diagram for TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >:

Inheritance graph
[legend]
Collaboration diagram for TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef TAO_ESF_Copy_On_Write_Read_Guard<
COLLECTION, ITERATOR, ACE_SYNCH_MUTEX_T
Read_Guard
 Constructor.
typedef TAO_ESF_Copy_On_Write_Write_Guard<
COLLECTION, ITERATOR, ACE_SYNCH_USE
Write_Guard

Public Member Functions

 TAO_ESF_Copy_On_Write (void)
 ~TAO_ESF_Copy_On_Write (void)
 Destructor.
virtual void for_each (TAO_ESF_Worker< PROXY > *worker)
virtual void connected (PROXY *proxy)
virtual void reconnected (PROXY *proxy)
virtual void disconnected (PROXY *proxy)
 Remove an element from the collection.
virtual void shutdown (void)
 The EC is shutting down, must release all the elements.

Private Types

typedef TAO_ESF_Copy_On_Write_Collection<
COLLECTION, ITERATOR > 
Collection

Private Attributes

ACE_SYNCH_MUTEX_T mutex_
 A mutex to serialize access to the collection pointer.
int pending_writes_
 Number of pending writes.
int writing_
ACE_SYNCH_CONDITION_T cond_
 A condition variable to wait to synchronize multiple writers.
Collectioncollection_
 The collection, with reference counting added.

Detailed Description

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL>
class TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >

TAO_ESF_Copy_On_Write.

Implement the Copy_On_Write protocol The class is parametric on the kind of collection and locking mechanism used.

Definition at line 123 of file ESF_Copy_On_Write.h.


Member Typedef Documentation

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
typedef TAO_ESF_Copy_On_Write_Collection<COLLECTION,ITERATOR> TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::Collection [private]

Definition at line 142 of file ESF_Copy_On_Write.h.

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
typedef TAO_ESF_Copy_On_Write_Read_Guard<COLLECTION,ITERATOR,ACE_SYNCH_MUTEX_T> TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::Read_Guard

Constructor.

Definition at line 127 of file ESF_Copy_On_Write.h.

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
typedef TAO_ESF_Copy_On_Write_Write_Guard<COLLECTION,ITERATOR,ACE_SYNCH_USE> TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::Write_Guard

Definition at line 128 of file ESF_Copy_On_Write.h.


Constructor & Destructor Documentation

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::TAO_ESF_Copy_On_Write ( void   ) 

Definition at line 45 of file ESF_Copy_On_Write.cpp.

References ACE_NEW.

00046       :  pending_writes_ (0),
00047          writing_ (0),
00048          cond_ (mutex_)
00049 {
00050   ACE_NEW (this->collection_, Collection);
00051 }

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::~TAO_ESF_Copy_On_Write ( void   ) 

Destructor.

Definition at line 55 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::_decr_refcnt(), ACE_GUARD, ACE_SYNCH_MUTEX_T, TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::collection_, and TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::cond_.

00056 {
00057   ACE_GUARD (ACE_SYNCH_MUTEX_T, ace_mon, this->mutex_);
00058 
00059   while (this->pending_writes_ != 0)
00060     this->cond_.wait ();
00061 
00062   this->collection_->_decr_refcnt ();
00063   this->collection_ = 0;
00064 }


Member Function Documentation

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
void TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::connected ( PROXY *  proxy  )  [virtual]

Insert a new element into the collection. The collection assumes ownership of the element.

Implements TAO_ESF_Proxy_Collection< PROXY >.

Definition at line 83 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::collection, and TAO_ESF_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR, >::copy.

00084 {
00085   Write_Guard ace_mon (this->mutex_,
00086                        this->cond_,
00087                        this->pending_writes_,
00088                        this->writing_,
00089                        this->collection_);
00090 
00091   proxy->_incr_refcnt ();
00092   ace_mon.copy->collection.connected (proxy);
00093 }

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
void TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::disconnected ( PROXY *  proxy  )  [virtual]

Remove an element from the collection.

Implements TAO_ESF_Proxy_Collection< PROXY >.

Definition at line 111 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::collection, and TAO_ESF_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR, >::copy.

00112 {
00113   Write_Guard ace_mon (this->mutex_,
00114                        this->cond_,
00115                        this->pending_writes_,
00116                        this->writing_,
00117                        this->collection_);
00118 
00119   ace_mon.copy->collection.disconnected (proxy);
00120 }

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
void TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::for_each ( TAO_ESF_Worker< PROXY > *  worker  )  [virtual]

Iterate over the collection and invoke worker->work() for each member of the collection. This encapsulates

Implements TAO_ESF_Proxy_Collection< PROXY >.

Definition at line 68 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::collection, TAO_ESF_Copy_On_Write_Read_Guard< COLLECTION, ITERATOR, ACE_LOCK >::collection, TAO_ESF_Worker< Object >::set_size(), and TAO_ESF_Worker< Object >::work().

00069 {
00070   Read_Guard ace_mon (this->mutex_,
00071                       this->collection_);
00072 
00073   worker->set_size(ace_mon.collection->collection.size());
00074   ITERATOR end = ace_mon.collection->collection.end ();
00075   for (ITERATOR i = ace_mon.collection->collection.begin (); i != end; ++i)
00076     {
00077       worker->work (*i);
00078     }
00079 }

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
void TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::reconnected ( PROXY *  proxy  )  [virtual]

Insert an element into the collection. No errors can be raised if the element is already present. The collection assumes ownership, i.e. must invoke <proxy->_decr_refcnt()> if the element is already present in the collection.

Implements TAO_ESF_Proxy_Collection< PROXY >.

Definition at line 97 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::collection, and TAO_ESF_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR, >::copy.

00098 {
00099   Write_Guard ace_mon (this->mutex_,
00100                        this->cond_,
00101                        this->pending_writes_,
00102                        this->writing_,
00103                        this->collection_);
00104 
00105   proxy->_incr_refcnt ();
00106   ace_mon.copy->collection.reconnected (proxy);
00107 }

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
void TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::shutdown ( void   )  [virtual]

The EC is shutting down, must release all the elements.

Implements TAO_ESF_Proxy_Collection< PROXY >.

Definition at line 123 of file ESF_Copy_On_Write.cpp.

References TAO_ESF_Copy_On_Write_Collection< COLLECTION, ITERATOR >::collection, and TAO_ESF_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR, >::copy.

00124 {
00125   // We need to perform a copy to follow the protocol.
00126   Write_Guard ace_mon (this->mutex_,
00127                        this->cond_,
00128                        this->pending_writes_,
00129                        this->writing_,
00130                        this->collection_);
00131 
00132   ace_mon.copy->collection.shutdown ();
00133 }


Member Data Documentation

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
Collection* TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::collection_ [private]

The collection, with reference counting added.

Definition at line 161 of file ESF_Copy_On_Write.h.

Referenced by TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::~TAO_ESF_Copy_On_Write().

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
ACE_SYNCH_CONDITION_T TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::cond_ [private]

A condition variable to wait to synchronize multiple writers.

Definition at line 158 of file ESF_Copy_On_Write.h.

Referenced by TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::~TAO_ESF_Copy_On_Write().

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
ACE_SYNCH_MUTEX_T TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::mutex_ [private]

A mutex to serialize access to the collection pointer.

Definition at line 145 of file ESF_Copy_On_Write.h.

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
int TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::pending_writes_ [private]

Number of pending writes.

Definition at line 148 of file ESF_Copy_On_Write.h.

template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL >
int TAO_ESF_Copy_On_Write< PROXY, COLLECTION, ITERATOR, >::writing_ [private]

If non-zero then a thread is changing the collection. Many threads can use the collection simulatenously, but only one change it.

Definition at line 155 of file ESF_Copy_On_Write.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:43:50 2010 for TAO_ESF by  doxygen 1.4.7