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  *  ESF_Copy_On_Write.h,v 1.10 2006/03/15 07:52:21 jtc Exp
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                          ACE_ENV_ARG_DECL);
00137   virtual void connected (PROXY *proxy
00138                           ACE_ENV_ARG_DECL);
00139   virtual void reconnected (PROXY *proxy
00140                             ACE_ENV_ARG_DECL);
00141   virtual void disconnected (PROXY *proxy
00142                              ACE_ENV_ARG_DECL);
00143   virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL);
00144 
00145 private:
00146   typedef TAO_ESF_Copy_On_Write_Collection<COLLECTION,ITERATOR> Collection;
00147 
00148   /// A mutex to serialize access to the collection pointer.
00149   ACE_SYNCH_MUTEX_T mutex_;
00150 
00151   /// Number of pending writes
00152   int pending_writes_;
00153 
00154   /**
00155    * If non-zero then a thread is changing the collection.  Many
00156    * threads can use the collection simulatenously, but only one
00157    * change it.
00158    */
00159   int writing_;
00160 
00161   /// A condition variable to wait to synchronize multiple writers.
00162   ACE_SYNCH_CONDITION_T cond_;
00163 
00164   /// The collection, with reference counting added
00165   Collection *collection_;
00166 };
00167 
00168 // ****************************************************************
00169 
00170 TAO_END_VERSIONED_NAMESPACE_DECL
00171 
00172 #if defined (__ACE_INLINE__)
00173 #include "orbsvcs/ESF/ESF_Copy_On_Write.i"
00174 #endif /* __ACE_INLINE__ */
00175 
00176 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00177 #include "orbsvcs/ESF/ESF_Copy_On_Write.cpp"
00178 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00179 
00180 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00181 #pragma implementation ("ESF_Copy_On_Write.cpp")
00182 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00183 
00184 #endif /* TAO_ESF_COPY_ON_WRITE_H */

Generated on Thu Nov 9 13:08:13 2006 for TAO_ESF by doxygen 1.3.6