2
// Future_Set.cpp,v 4.12 2000/05/17 23:31:05 brunsch Exp
4
#ifndef ACE_FUTURE_SET_CPP
5
#define ACE_FUTURE_SET_CPP
7
#include "ace/Future_Set.h"
9
#if !defined (ACE_LACKS_PRAGMA_ONCE)
11
#endif /* ACE_LACKS_PRAGMA_ONCE */
13
ACE_RCSID (ace, Future_Set, "Future_Set.cpp,v 4.12 2000/05/17 23:31:05 brunsch Exp")
15
#if defined (ACE_HAS_THREADS)
18
ACE_Future_Set<T>::ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *new_queue)
22
this->future_notification_queue_ = new_queue;
25
ACE_NEW (this->future_notification_queue_,
26
ACE_Message_Queue<ACE_SYNCH>);
27
this->delete_queue_ = 1;
32
ACE_Future_Set<T>::~ACE_Future_Set (void)
34
// Detach ourselves from all remaining futures, if any, in our map.
35
ACE_TYPENAME FUTURE_HASH_MAP::iterator iterator =
36
this->future_map_.begin ();
38
ACE_TYPENAME FUTURE_HASH_MAP::iterator end =
39
this->future_map_.end ();
45
FUTURE_HOLDER *future_holder = (*iterator).int_id_;
46
future_holder->item_.detach (this);
50
if (this->delete_queue_ != 0)
51
delete this->future_notification_queue_;
54
template <class T> int
55
ACE_Future_Set<T>::is_empty () const
57
return (((ACE_Future_Set<T>*)this)->future_map_.current_size () == 0 );
60
template <class T> int
61
ACE_Future_Set<T>::insert (ACE_Future<T> &future)
63
FUTURE_HOLDER *future_holder;
64
ACE_NEW_RETURN (future_holder,
65
FUTURE_HOLDER (future),
68
FUTURE_REP *future_rep = future.get_rep ();
69
int result = this->future_map_.bind (future_rep,
72
// If a new map entry was created, then attach to the future,
73
// otherwise we were already attached to the future or some error
74
// occurred so just delete the future holder.
76
// Attach ourself to the ACE_Futures list of observer
84
template <class T> void
85
ACE_Future_Set<T>::update (const ACE_Future<T> &future)
87
ACE_Message_Block *mb;
88
FUTURE &local_future = ACE_const_cast (ACE_Future<T> &, future);
91
ACE_Message_Block ((char *) local_future.get_rep (), 0));
93
// Enqueue in priority order.
94
this->future_notification_queue_->enqueue (mb, 0);
97
template <class T> int
98
ACE_Future_Set<T>::next_readable (ACE_Future<T> &future,
101
if (this->is_empty ())
104
ACE_Message_Block *mb = 0;
105
FUTURE_REP *future_rep = 0;
107
// Wait for a "readable future" signal from the message queue.
108
if (this->future_notification_queue_->dequeue_head (mb,
111
// Extract future rep from the message block.
113
ACE_reinterpret_cast (FUTURE_REP *,
116
// Delete the message block.
122
// Remove the hash map entry with the specified future rep from our map.
123
FUTURE_HOLDER *future_holder;
124
if ( this->future_map_.find (future_rep,
125
future_holder) != -1 )
127
future = future_holder->item_;
128
this->future_map_.unbind (future_rep);
129
delete future_holder;
136
#endif /* ACE_HAS_THREADS */
137
#endif /* ACE_FUTURE_SET_CPP */