ESF_Copy_On_Write.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   ESF_Copy_On_Write.h
00005  *
00006  *  $Id: ESF_Copy_On_Write.h 80179 2007-12-03 19:07:10Z sowayaa $
00007  *
00008  *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
00009  *
00010  *  http://doc.ece.uci.edu/~coryan/EC/index.html
00011  */
00012 
00013 #ifndef TAO_ESF_COPY_ON_WRITE_H
00014 #define TAO_ESF_COPY_ON_WRITE_H
00015 
00016 #include "orbsvcs/ESF/ESF_Proxy_Collection.h"
00017 
00018 #include "tao/Basic_Types.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 template<class COLLECTION, class ITERATOR>
00027 class TAO_ESF_Copy_On_Write_Collection
00028 {
00029 public:
00030   TAO_ESF_Copy_On_Write_Collection (void);
00031 
00032   /// Increment the reference count
00033   CORBA::ULong _incr_refcnt (void);
00034 
00035   /// Decrement the reference count
00036   CORBA::ULong _decr_refcnt (void);
00037 
00038   /// The actual collection
00039   COLLECTION collection;
00040 
00041 private:
00042   /// The reference count
00043   CORBA::ULong refcount_;
00044 };
00045 
00046 // ****************************************************************
00047 
00048 /**
00049  * @class TAO_ESF_Copy_On_Write_Read_Guard
00050  *
00051  * @brief TAO_ESF_Copy_On_Write_Read_Guard
00052  *
00053  * This helper class atomically increments the reference count of
00054  * a TAO_ESF_Copy_On_Write_Collection and reads the current
00055  * collection in the Copy_On_Write class.
00056  */
00057 template<class COLLECTION, class ITERATOR, class ACE_LOCK>
00058 class TAO_ESF_Copy_On_Write_Read_Guard
00059 {
00060 public:
00061   /// Constructor
00062   typedef TAO_ESF_Copy_On_Write_Collection<COLLECTION,ITERATOR> Collection;
00063   TAO_ESF_Copy_On_Write_Read_Guard (ACE_LOCK &mutex,
00064                                     Collection *&collection);
00065 
00066   /// Destructor
00067   ~TAO_ESF_Copy_On_Write_Read_Guard (void);
00068 
00069   Collection *collection;
00070 
00071 private:
00072   ACE_LOCK &mutex;
00073 };
00074 
00075 // ****************************************************************
00076 
00077 /**
00078  * @class TAO_ESF_Copy_On_Write_Write_Guard
00079  *
00080  * @brief TAO_ESF_Copy_On_Write_Write_Guard
00081  *
00082  * This helper class atomically increments the reference count of
00083  * a TAO_ESF_Copy_On_Write_Collection and reads the current
00084  * collection in the Copy_On_Write class.
00085  */
00086 template<class COLLECTION, class ITERATOR, ACE_SYNCH_DECL>
00087 class TAO_ESF_Copy_On_Write_Write_Guard
00088 {
00089 public:
00090   /// Constructor
00091   typedef TAO_ESF_Copy_On_Write_Collection<COLLECTION,ITERATOR> Collection;
00092   TAO_ESF_Copy_On_Write_Write_Guard (ACE_SYNCH_MUTEX_T &mutex,
00093                                      ACE_SYNCH_CONDITION_T &cond,
00094                                      int &pending_writes,
00095                                      int &writing_flag,
00096                                      Collection*& collection);
00097 
00098   /// Destructor
00099   ~TAO_ESF_Copy_On_Write_Write_Guard (void);
00100 
00101   Collection *copy;
00102 
00103 private:
00104   ACE_SYNCH_MUTEX_T &mutex;
00105   ACE_SYNCH_CONDITION_T &cond;
00106   int &pending_writes;
00107   int &writing_flag;
00108   Collection *&collection;
00109 };
00110 
00111 // ****************************************************************
00112 
00113 /**
00114  * @class TAO_ESF_Copy_On_Write
00115  *
00116  * @brief TAO_ESF_Copy_On_Write
00117  *
00118  * Implement the Copy_On_Write protocol
00119  * The class is parametric on the kind of collection and locking
00120  * mechanism used.
00121  */
00122 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL>
00123 class TAO_ESF_Copy_On_Write : public TAO_ESF_Proxy_Collection<PROXY>
00124 {
00125 public:
00126   /// Constructor
00127   typedef TAO_ESF_Copy_On_Write_Read_Guard<COLLECTION,ITERATOR,ACE_SYNCH_MUTEX_T> Read_Guard;
00128   typedef TAO_ESF_Copy_On_Write_Write_Guard<COLLECTION,ITERATOR,ACE_SYNCH_USE> Write_Guard;
00129   TAO_ESF_Copy_On_Write (void);
00130 
00131   /// Destructor
00132   ~TAO_ESF_Copy_On_Write (void);
00133 
00134   // = The TAO_ESF_Proxy methods
00135   virtual void for_each (TAO_ESF_Worker<PROXY> *worker);
00136   virtual void connected (PROXY *proxy);
00137   virtual void reconnected (PROXY *proxy);
00138   virtual void disconnected (PROXY *proxy);
00139   virtual void shutdown (void);
00140 
00141 private:
00142   typedef TAO_ESF_Copy_On_Write_Collection<COLLECTION,ITERATOR> Collection;
00143 
00144   /// A mutex to serialize access to the collection pointer.
00145   ACE_SYNCH_MUTEX_T mutex_;
00146 
00147   /// Number of pending writes
00148   int pending_writes_;
00149 
00150   /**
00151    * If non-zero then a thread is changing the collection.  Many
00152    * threads can use the collection simulatenously, but only one
00153    * change it.
00154    */
00155   int writing_;
00156 
00157   /// A condition variable to wait to synchronize multiple writers.
00158   ACE_SYNCH_CONDITION_T cond_;
00159 
00160   /// The collection, with reference counting added
00161   Collection *collection_;
00162 };
00163 
00164 // ****************************************************************
00165 
00166 TAO_END_VERSIONED_NAMESPACE_DECL
00167 
00168 #if defined (__ACE_INLINE__)
00169 #include "orbsvcs/ESF/ESF_Copy_On_Write.inl"
00170 #endif /* __ACE_INLINE__ */
00171 
00172 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00173 #include "orbsvcs/ESF/ESF_Copy_On_Write.cpp"
00174 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00175 
00176 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00177 #pragma implementation ("ESF_Copy_On_Write.cpp")
00178 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00179 
00180 #endif /* TAO_ESF_COPY_ON_WRITE_H */

Generated on Tue Feb 2 17:43:47 2010 for TAO_ESF by  doxygen 1.4.7