Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ACE_RMCast_Copy_On_Write_Write_Guard Class Template Reference

Implement the write guard for a reference counted collecion. More...

#include <RMCast_Copy_On_Write.h>

Collaboration diagram for ACE_RMCast_Copy_On_Write_Write_Guard:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_RMCast_Copy_On_Write_Collection<
COLLECTION, ITERATOR > 
Collection
typedef ACE_RMCast_Copy_On_Write_Container<
COLLECTION, ITERATOR > 
Container

Public Methods

 ACE_RMCast_Copy_On_Write_Write_Guard (Container &container)
 Constructor. More...

 ~ACE_RMCast_Copy_On_Write_Write_Guard (void)
 Destructor. More...


Public Attributes

Collectioncopy
 The collection. More...


Private Attributes

ACE_SYNCH_MUTEXmutex
 Keep a reference to the mutex. More...

ACE_SYNCH_CONDITIONcond
 Keep a reference to the condition variable. More...

int & pending_writes
 Use a reference to update the pending writes count. More...

int & writing_flag
 Use a reference to update the writing flag. More...

Collection *& collection
 Use this reference to update the collection once the modifications are finished. More...


Detailed Description

template<class COLLECTION, class ITERATOR>
class ACE_RMCast_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR >

Implement the write guard for a reference counted collecion.

This helper class atomically increments the reference count of a ACE_RMCast_Copy_On_Write_Collection and reads the current collection in the Copy_On_Write class.

Definition at line 113 of file RMCast_Copy_On_Write.h.


Member Typedef Documentation

template<class COLLECTION, class ITERATOR>
typedef ACE_RMCast_Copy_On_Write_Collection<COLLECTION,ITERATOR> ACE_RMCast_Copy_On_Write_Write_Guard::Collection
 

Definition at line 116 of file RMCast_Copy_On_Write.h.

template<class COLLECTION, class ITERATOR>
typedef ACE_RMCast_Copy_On_Write_Container<COLLECTION,ITERATOR> ACE_RMCast_Copy_On_Write_Write_Guard::Container
 

Definition at line 117 of file RMCast_Copy_On_Write.h.


Constructor & Destructor Documentation

template<class COLLECTION, class ITERATOR>
ACE_RMCast_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR >::ACE_RMCast_Copy_On_Write_Write_Guard Container   container
 

Constructor.

Definition at line 147 of file RMCast_Copy_On_Write.cpp.

References ACE_GUARD, ACE_NEW, ACE_SYNCH_MUTEX, collection, ACE_RMCast_Copy_On_Write_Collection::collection, cond, copy, pending_writes, and writing_flag.

00148   : copy (0)
00149   , mutex (container.mutex_)
00150   , cond (container.cond_)
00151   , pending_writes (container.pending_writes_)
00152   , writing_flag (container.writing_)
00153   , collection (container.collection_)
00154 {
00155   {
00156     ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex);
00157 
00158     this->pending_writes++;
00159 
00160     while (this->writing_flag != 0)
00161       this->cond.wait ();
00162 
00163     this->writing_flag = 1;
00164   }
00165 
00166   // Copy outside the mutex, because it may take a long time.
00167   // Nobody can change it, because it is protected by the
00168   // writing_flag.
00169 
00170   // First initialize it (with the correct reference count
00171   ACE_NEW (this->copy, Collection);
00172   // Copy the contents
00173   this->copy->collection = this->collection->collection;
00174 }

template<class COLLECTION, class ITERATOR>
ACE_RMCast_Copy_On_Write_Write_Guard< COLLECTION, ITERATOR >::~ACE_RMCast_Copy_On_Write_Write_Guard void   
 

Destructor.

Definition at line 178 of file RMCast_Copy_On_Write.cpp.

References ACE_RMCast_Copy_On_Write_Collection::_decr_refcnt, ACE_GUARD, ACE_SYNCH_MUTEX, collection, cond, copy, pending_writes, and writing_flag.

00179 {
00180   Collection *tmp = 0;
00181   {
00182     ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex);
00183 
00184     tmp = this->collection;
00185     this->collection = this->copy;
00186     this->writing_flag = 0;
00187     this->pending_writes--;
00188 
00189     this->cond.signal ();
00190   }
00191   // Delete outside the mutex, because it may take a long time.
00192   // @@ Is this right?  What happens if several readers are still
00193   // using the old copy?
00194   tmp->_decr_refcnt ();
00195 }


Member Data Documentation

template<class COLLECTION, class ITERATOR>
Collection*& ACE_RMCast_Copy_On_Write_Write_Guard::collection [private]
 

Use this reference to update the collection once the modifications are finished.

Definition at line 143 of file RMCast_Copy_On_Write.h.

Referenced by ACE_RMCast_Copy_On_Write_Write_Guard, and ~ACE_RMCast_Copy_On_Write_Write_Guard.

template<class COLLECTION, class ITERATOR>
ACE_SYNCH_CONDITION& ACE_RMCast_Copy_On_Write_Write_Guard::cond [private]
 

Keep a reference to the condition variable.

Definition at line 133 of file RMCast_Copy_On_Write.h.

Referenced by ACE_RMCast_Copy_On_Write_Write_Guard, and ~ACE_RMCast_Copy_On_Write_Write_Guard.

template<class COLLECTION, class ITERATOR>
Collection* ACE_RMCast_Copy_On_Write_Write_Guard::copy
 

The collection.

Definition at line 126 of file RMCast_Copy_On_Write.h.

Referenced by ACE_RMCast_Copy_On_Write_Write_Guard, ACE_RMCast_Copy_On_Write::bind_i, ACE_RMCast_Copy_On_Write::unbind_i, and ~ACE_RMCast_Copy_On_Write_Write_Guard.

template<class COLLECTION, class ITERATOR>
ACE_SYNCH_MUTEX& ACE_RMCast_Copy_On_Write_Write_Guard::mutex [private]
 

Keep a reference to the mutex.

Definition at line 130 of file RMCast_Copy_On_Write.h.

template<class COLLECTION, class ITERATOR>
int& ACE_RMCast_Copy_On_Write_Write_Guard::pending_writes [private]
 

Use a reference to update the pending writes count.

Definition at line 136 of file RMCast_Copy_On_Write.h.

Referenced by ACE_RMCast_Copy_On_Write_Write_Guard, and ~ACE_RMCast_Copy_On_Write_Write_Guard.

template<class COLLECTION, class ITERATOR>
int& ACE_RMCast_Copy_On_Write_Write_Guard::writing_flag [private]
 

Use a reference to update the writing flag.

Definition at line 139 of file RMCast_Copy_On_Write.h.

Referenced by ACE_RMCast_Copy_On_Write_Write_Guard, and ~ACE_RMCast_Copy_On_Write_Write_Guard.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 13:13:55 2003 for ACE_RMCast by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002