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

Future_Set.cpp

Go to the documentation of this file.
00001 // Future.cpp
00002 // $Id: Future_Set.cpp,v 1.1.1.3 2001/12/04 14:33:01 chad Exp $
00003 
00004 #ifndef ACE_FUTURE_SET_CPP
00005 #define ACE_FUTURE_SET_CPP
00006 
00007 #include "ace/Future_Set.h"
00008 
00009 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00010 #pragma once
00011 #endif /* ACE_LACKS_PRAGMA_ONCE */
00012 
00013 ACE_RCSID (ace, Future_Set, "$Id: Future_Set.cpp,v 1.1.1.3 2001/12/04 14:33:01 chad Exp $")
00014 
00015 #if defined (ACE_HAS_THREADS)
00016 
00017 template <class T>
00018 ACE_Future_Set<T>::ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *new_queue)
00019   : delete_queue_ (0)
00020 {
00021   if (new_queue)
00022     this->future_notification_queue_ = new_queue;
00023   else
00024     {
00025       ACE_NEW (this->future_notification_queue_,
00026                ACE_Message_Queue<ACE_SYNCH>);
00027       this->delete_queue_ = 1;
00028     }
00029 }
00030 
00031 template <class T>
00032 ACE_Future_Set<T>::~ACE_Future_Set (void)
00033 {
00034   // Detach ourselves from all remaining futures, if any, in our map.
00035   ACE_TYPENAME FUTURE_HASH_MAP::iterator iterator =
00036     this->future_map_.begin ();
00037 
00038   ACE_TYPENAME FUTURE_HASH_MAP::iterator end =
00039     this->future_map_.end ();
00040 
00041   for (;
00042        iterator != end;
00043        ++iterator)
00044     {
00045       FUTURE_HOLDER *future_holder = (*iterator).int_id_;
00046       future_holder->item_.detach (this);
00047       delete future_holder;
00048     }
00049 
00050   if (this->delete_queue_ != 0)
00051     delete this->future_notification_queue_;
00052 }
00053 
00054 template <class T> int
00055 ACE_Future_Set<T>::is_empty () const
00056 {
00057   return (((ACE_Future_Set<T>*)this)->future_map_.current_size () == 0 );
00058 }
00059 
00060 template <class T> int
00061 ACE_Future_Set<T>::insert (ACE_Future<T> &future)
00062 {
00063   FUTURE_HOLDER *future_holder;
00064   ACE_NEW_RETURN (future_holder,
00065                   FUTURE_HOLDER (future),
00066                   -1);
00067 
00068   FUTURE_REP *future_rep = future.get_rep ();
00069   int result = this->future_map_.bind (future_rep,
00070                                        future_holder);
00071 
00072   // If a new map entry was created, then attach to the future,
00073   // otherwise we were already attached to the future or some error
00074   // occurred so just delete the future holder.
00075   if ( result == 0 )
00076     // Attach ourself to the ACE_Futures list of observer
00077     future.attach (this);
00078   else
00079     delete future_holder;
00080 
00081   return result;
00082 }
00083 
00084 template <class T> void
00085 ACE_Future_Set<T>::update (const ACE_Future<T> &future)
00086 {
00087   ACE_Message_Block *mb;
00088   FUTURE &local_future = ACE_const_cast (ACE_Future<T> &, future);
00089 
00090   ACE_NEW (mb,
00091            ACE_Message_Block ((char *) local_future.get_rep (), 0));
00092 
00093   // Enqueue in priority order.
00094   this->future_notification_queue_->enqueue (mb, 0);
00095 }
00096 
00097 template <class T> int
00098 ACE_Future_Set<T>::next_readable (ACE_Future<T> &future,
00099                                   ACE_Time_Value *tv)
00100 {
00101   if (this->is_empty ())
00102     return 0;
00103 
00104   ACE_Message_Block *mb = 0;
00105   FUTURE_REP *future_rep = 0;
00106 
00107   // Wait for a "readable future" signal from the message queue.
00108   if (this->future_notification_queue_->dequeue_head (mb,
00109                                                       tv) != -1)
00110     {
00111       // Extract future rep from the message block.
00112       future_rep =
00113         ACE_reinterpret_cast (FUTURE_REP *,
00114                               mb->base ());
00115 
00116       // Delete the message block.
00117       mb->release ();
00118     }
00119   else
00120     return 0;
00121 
00122   // Remove the hash map entry with the specified future rep from our map.
00123   FUTURE_HOLDER *future_holder;
00124   if ( this->future_map_.find (future_rep,
00125                                future_holder) != -1 )
00126     {
00127       future = future_holder->item_;
00128       this->future_map_.unbind (future_rep);
00129       delete future_holder;
00130       return 1;
00131     }
00132 
00133   return 0;
00134 }
00135 
00136 #endif /* ACE_HAS_THREADS */
00137 #endif /* ACE_FUTURE_SET_CPP */

Generated on Mon Jun 16 11:19:44 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002