ACE_Future_Set< T > Class Template Reference

This class implements a mechanism which allows the values of a collection of ACE_Future objects to be accessed by reader threads as they become available. The caller(s) provide the ACE_Future_Set (i.e. the observer...) with the collection of ACE_Future objects (i.e. the subjects...) that are to be observed using the the ACE_Future_Set::insert() method. The caller(s) may then iterate over the collection in the order in which they become readable using the ACE_Future_Set::next_readable() method. More...

#include <Future_Set.h>

Inheritance diagram for ACE_Future_Set< T >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Future_Set< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Future_Set (ACE_Message_Queue< ACE_SYNCH > *future_notification_queue_=0)
 Constructor.

 ~ACE_Future_Set (void)
 Destructor.

int is_empty (void) const
int insert (ACE_Future< T > &future)
int next_readable (ACE_Future< T > &result, ACE_Time_Value *tv=0)
virtual void update (const ACE_Future< T > &future)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Types

typedef ACE_Future< T > FUTURE
typedef ACE_Future_Rep< T > FUTURE_REP
typedef ACE_Future_Holder< T > FUTURE_HOLDER
typedef ACE_Pointer_Hash<
FUTURE_REP * > 
FUTURE_REP_HASH
typedef ACE_Equal_To< FUTURE_REP * > FUTURE_REP_COMPARE
typedef ACE_Hash_Map_Manager_Ex<
FUTURE_REP *, FUTURE_HOLDER *,
FUTURE_REP_HASH, FUTURE_REP_COMPARE,
ACE_Null_Mutex
FUTURE_HASH_MAP

Private Member Functions

void operator= (const ACE_Future_Set< T > &)
 ACE_Future_Set (const ACE_Future_Set< T > &)

Private Attributes

FUTURE_HASH_MAP future_map_
ACE_Message_Queue< ACE_SYNCH > * future_notification_queue_
int delete_queue_
 Keeps track of whether we need to delete the message queue.


Detailed Description

template<class T>
class ACE_Future_Set< T >

This class implements a mechanism which allows the values of a collection of ACE_Future objects to be accessed by reader threads as they become available. The caller(s) provide the ACE_Future_Set (i.e. the observer...) with the collection of ACE_Future objects (i.e. the subjects...) that are to be observed using the the ACE_Future_Set::insert() method. The caller(s) may then iterate over the collection in the order in which they become readable using the ACE_Future_Set::next_readable() method.

Definition at line 44 of file Future_Set.h.


Member Typedef Documentation

template<class T>
typedef ACE_Future<T> ACE_Future_Set< T >::FUTURE [private]
 

Definition at line 106 of file Future_Set.h.

Referenced by ACE_Future_Set< T >::update().

template<class T>
typedef ACE_Hash_Map_Manager_Ex<FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex> ACE_Future_Set< T >::FUTURE_HASH_MAP [private]
 

Definition at line 120 of file Future_Set.h.

template<class T>
typedef ACE_Future_Holder<T> ACE_Future_Set< T >::FUTURE_HOLDER [private]
 

Definition at line 110 of file Future_Set.h.

Referenced by ACE_Future_Set< T >::insert(), ACE_Future_Set< T >::next_readable(), and ACE_Future_Set< T >::~ACE_Future_Set().

template<class T>
typedef ACE_Future_Rep<T> ACE_Future_Set< T >::FUTURE_REP [private]
 

Definition at line 108 of file Future_Set.h.

template<class T>
typedef ACE_Equal_To<FUTURE_REP *> ACE_Future_Set< T >::FUTURE_REP_COMPARE [private]
 

Definition at line 114 of file Future_Set.h.

template<class T>
typedef ACE_Pointer_Hash<FUTURE_REP *> ACE_Future_Set< T >::FUTURE_REP_HASH [private]
 

Definition at line 112 of file Future_Set.h.


Constructor & Destructor Documentation

template<class T>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Future_Set< T >::ACE_Future_Set ACE_Message_Queue< ACE_SYNCH > *  future_notification_queue_ = 0  ) 
 

Constructor.

Definition at line 17 of file Future_Set.cpp.

References ACE_NEW, and ACE_Future_Set< T >::future_notification_queue_.

00018   : delete_queue_ (0)
00019 {
00020   if (new_queue)
00021     this->future_notification_queue_ = new_queue;
00022   else
00023     {
00024       ACE_NEW (this->future_notification_queue_,
00025                ACE_Message_Queue<ACE_SYNCH>);
00026       this->delete_queue_ = 1;
00027     }
00028 }

template<class T>
ACE_Future_Set< T >::~ACE_Future_Set void   ) 
 

Destructor.

Definition at line 31 of file Future_Set.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::end(), ACE_Future_Set< T >::FUTURE_HOLDER, ACE_Future_Set< T >::future_map_, ACE_Future_Set< T >::future_notification_queue_, and ACE_Future_Holder< T >::item_.

00032 {
00033   // Detach ourselves from all remaining futures, if any, in our map.
00034   ACE_TYPENAME FUTURE_HASH_MAP::iterator iterator =
00035     this->future_map_.begin ();
00036 
00037   ACE_TYPENAME FUTURE_HASH_MAP::iterator end =
00038     this->future_map_.end ();
00039 
00040   for (;
00041        iterator != end;
00042        ++iterator)
00043     {
00044       FUTURE_HOLDER *future_holder = (*iterator).int_id_;
00045       future_holder->item_.detach (this);
00046       delete future_holder;
00047     }
00048 
00049   if (this->delete_queue_ != 0)
00050     delete this->future_notification_queue_;
00051 }

template<class T>
ACE_Future_Set< T >::ACE_Future_Set const ACE_Future_Set< T > &   )  [private]
 


Member Function Documentation

template<class T>
int ACE_Future_Set< T >::insert ACE_Future< T > &  future  ) 
 

Enqueus the given ACE_Future into this objects queue when it is readable.

Returns 0 if the future is successfully inserted, 1 if the future is already inserted, and -1 if failures occur.

Definition at line 60 of file Future_Set.cpp.

References ACE_NEW_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), ACE_Future_Set< T >::FUTURE_HOLDER, and ACE_Future_Set< T >::future_map_.

00061 {
00062   FUTURE_HOLDER *future_holder;
00063   ACE_NEW_RETURN (future_holder,
00064                   FUTURE_HOLDER (future),
00065                   -1);
00066 
00067   FUTURE_REP *future_rep = future.get_rep ();
00068   int result = this->future_map_.bind (future_rep,
00069                                        future_holder);
00070 
00071   // If a new map entry was created, then attach to the future,
00072   // otherwise we were already attached to the future or some error
00073   // occurred so just delete the future holder.
00074   if ( result == 0 )
00075     // Attach ourself to the ACE_Futures list of observer
00076     future.attach (this);
00077   else
00078     delete future_holder;
00079 
00080   return result;
00081 }

template<class T>
int ACE_Future_Set< T >::is_empty void   )  const
 

Return 1 if their are no ACE_Future objects left on its queue and 0 otherwise.

When an ACE_Future_Set has no ACE_Future>subjects to observe it is empty. The ACE_Future_Set is in the empty state when either the caller(s) have retrieved every readable ACE_Future subject assigned the ACE_Future_Set via the ACE_Future_Set::next_readable() method, or when the ACE_Future_Set has not been assigned any subjects.

Definition at line 54 of file Future_Set.cpp.

Referenced by ACE_Future_Set< T >::next_readable().

00055 {
00056   return (((ACE_Future_Set<T>*)this)->future_map_.current_size () == 0 );
00057 }

template<class T>
int ACE_Future_Set< T >::next_readable ACE_Future< T > &  result,
ACE_Time_Value tv = 0
 

Wait up to time to get the . Note that must be specified in absolute time rather than relative time.); get the next ACE_Future that is readable. If = 0, the will block forever.

If a readable future becomes available, then the input ACE_Future object param will be assigned with it and 1 will be returned. If the ACE_Future_Set is empty (i.e. see definition of ACE_Future_Set::is_empty()), then 0 is returned.

When a readable ACE_Future object is retrieved via the ACE_Future_Set::next_readable() method, the ACE_Future_Set will remove that ACE_Future object from its list of subjects.

Definition at line 97 of file Future_Set.cpp.

References ACE_Message_Block::base(), ACE_Message_Queue< ACE_SYNCH >::dequeue_head(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), ACE_Future_Set< T >::FUTURE_HOLDER, ACE_Future_Set< T >::future_map_, ACE_Future_Set< T >::future_notification_queue_, ACE_Future_Set< T >::is_empty(), ACE_Future_Holder< T >::item_, ACE_Message_Block::release(), and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind().

00099 {
00100   if (this->is_empty ())
00101     return 0;
00102 
00103   ACE_Message_Block *mb = 0;
00104   FUTURE_REP *future_rep = 0;
00105 
00106   // Wait for a "readable future" signal from the message queue.
00107   if (this->future_notification_queue_->dequeue_head (mb,
00108                                                       tv) != -1)
00109     {
00110       // Extract future rep from the message block.
00111       future_rep = reinterpret_cast<FUTURE_REP *> (mb->base ());
00112 
00113       // Delete the message block.
00114       mb->release ();
00115     }
00116   else
00117     return 0;
00118 
00119   // Remove the hash map entry with the specified future rep from our map.
00120   FUTURE_HOLDER *future_holder;
00121   if (this->future_map_.find (future_rep,
00122                               future_holder) != -1)
00123     {
00124       future = future_holder->item_;
00125       this->future_map_.unbind (future_rep);
00126       delete future_holder;
00127       return 1;
00128     }
00129 
00130   return 0;
00131 }

template<class T>
void ACE_Future_Set< T >::operator= const ACE_Future_Set< T > &   )  [private]
 

template<class T>
void ACE_Future_Set< T >::update const ACE_Future< T > &  future  )  [virtual]
 

Called by the ACE_Future subject in which we are subscribed to when its value is written to.

Implements ACE_Future_Observer< T >.

Definition at line 84 of file Future_Set.cpp.

References ACE_NEW, ACE_Message_Queue< ACE_SYNCH >::enqueue(), ACE_Future_Set< T >::FUTURE, ACE_Future_Set< T >::future_notification_queue_, and ACE_Future< T >::get_rep().

00085 {
00086   ACE_Message_Block *mb;
00087   FUTURE &local_future = const_cast<ACE_Future<T> &> (future);
00088 
00089   ACE_NEW (mb,
00090            ACE_Message_Block ((char *) local_future.get_rep (), 0));
00091 
00092   // Enqueue in priority order.
00093   this->future_notification_queue_->enqueue (mb, 0);
00094 }


Member Data Documentation

template<class T>
ACE_Future_Set< T >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_Future_Observer< T >.

Definition at line 99 of file Future_Set.h.

template<class T>
int ACE_Future_Set< T >::delete_queue_ [private]
 

Keeps track of whether we need to delete the message queue.

Definition at line 131 of file Future_Set.h.

template<class T>
FUTURE_HASH_MAP ACE_Future_Set< T >::future_map_ [private]
 

Map of , subjects, which have not been written to by client's writer thread.

Definition at line 124 of file Future_Set.h.

Referenced by ACE_Future_Set< T >::insert(), ACE_Future_Set< T >::next_readable(), and ACE_Future_Set< T >::~ACE_Future_Set().

template<class T>
ACE_Message_Queue<ACE_SYNCH>* ACE_Future_Set< T >::future_notification_queue_ [private]
 

Message queue for notifying the reader thread of which have been written to by client's writer thread.

Definition at line 128 of file Future_Set.h.

Referenced by ACE_Future_Set< T >::ACE_Future_Set(), ACE_Future_Set< T >::next_readable(), ACE_Future_Set< T >::update(), and ACE_Future_Set< T >::~ACE_Future_Set().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:35 2006 for ACE by doxygen 1.3.6