summaryrefslogtreecommitdiff
path: root/ace/Future_Set.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-28 23:32:00 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-28 23:32:00 +0000
commit4091f79cfee193a77e2384a3a33dc38347ef6acb (patch)
treedbb1e00111aef87e5d662206ba1ec33f82724140 /ace/Future_Set.cpp
parent2011599cafe9775821ac246ace3a84709f87642f (diff)
downloadATCD-4091f79cfee193a77e2384a3a33dc38347ef6acb.tar.gz
.
Diffstat (limited to 'ace/Future_Set.cpp')
-rw-r--r--ace/Future_Set.cpp96
1 files changed, 55 insertions, 41 deletions
diff --git a/ace/Future_Set.cpp b/ace/Future_Set.cpp
index 58a7ec6fba6..f2d7281eb41 100644
--- a/ace/Future_Set.cpp
+++ b/ace/Future_Set.cpp
@@ -17,7 +17,7 @@ ACE_RCSID(ace, Future_Set, "$Id$")
#if defined (ACE_HAS_THREADS)
template <class T>
-ACE_Future_Set<T>::ACE_Future_Set(ACE_Message_Queue<ACE_SYNCH> *new_queue)
+ACE_Future_Set<T>::ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *new_queue)
: delete_queue_ (0)
{
if (new_queue)
@@ -31,21 +31,25 @@ ACE_Future_Set<T>::ACE_Future_Set(ACE_Message_Queue<ACE_SYNCH> *new_queue)
}
template <class T>
-ACE_Future_Set<T>::ACE_Future_Set(const ACE_Future_Set<T> &r)
+ACE_Future_Set<T>::ACE_Future_Set (const ACE_Future_Set<T> &r)
{
}
template <class T>
-ACE_Future_Set<T>::~ACE_Future_Set(void)
+ACE_Future_Set<T>::~ACE_Future_Set (void)
{
+ FUTURE_HASH_ENTRY *map_entry = 0
+
// Detach ourselves from all remaining futures, if any,
- // in our list.
- for (FUTURE_NODE *node = this->future_list_.delete_head ();
- node != 0;
- node = this->future_list_.delete_head ())
+ // in our map.
+
+ for (FUTURE_HASH_ITERATOR map_iterator (this->future_map_);
+ map_iterator.next (map_entry) != 0;
+ map_iterator.advance ())
{
- node->item_.detach (this);
- delete node;
+ FUTURE_HOLDER *future_holder = map_entry->int_id_;
+ future_holder->item_.detach (this);
+ delete future_holder;
}
if (this->delete_queue_ != 0)
@@ -53,29 +57,42 @@ ACE_Future_Set<T>::~ACE_Future_Set(void)
}
template <class T> int
-ACE_Future_Set<T>::is_empty() const
+ACE_Future_Set<T>::is_empty () const
{
- return this->future_list_.is_empty ();
+ return this->future_map_.current_size () == 0;
}
-template <class T> void
+template <class T> int
ACE_Future_Set<T>::insert (ACE_Future<T> &future)
{
- FUTURE_NODE *node;
- ACE_NEW (node,
- FUTURE_NODE (future));
- this->future_list_.insert_tail (node);
+ FUTURE_HOLDER *future_holder;
+ ACE_NEW_RETURN (future_holder,
+ FUTURE_HOLDER (future),
+ -1);
+
+ FUTURE_REP_HASH_ADDR future_rep_hash_addr (future.get_rep ());
+ int result = this->future_map_.bind (future_rep_hash_addr,
+ future_holder);
+
+ // If a new map entry was created, then attach to the future,
+ // otherwise we were already attached to the future or some error
+ // occurred so just delete the future holder.
+ if (result == 0)
+ // Attach ourself to the ACE_Futures list of observer
+ future.attach (this);
+ else
+ delete future_holder;
- // Attach ourself to the ACE_Futures list of observer
- future.attach (this);
+ return result;
}
template <class T> void
ACE_Future_Set<T>::update (const ACE_Future<T> &future)
{
ACE_Message_Block *mb;
+ FUTURE localFuture = future;
ACE_NEW (mb,
- ACE_Message_Block ((char *) 0, 0));
+ ACE_Message_Block ((char *) localFuture.get_rep (), 0));
// Enqueue in priority order.
this->future_notification_queue_->enqueue (mb, 0);
@@ -89,36 +106,34 @@ ACE_Future_Set<T>::next_readable (ACE_Future<T> &future,
return 0;
ACE_Message_Block *mb;
+ FUTURE_REP *future_rep;
// Wait for a "readable future" signal from the message queue.
if (this->future_notification_queue_->dequeue_head (mb,
tv) != -1)
- // Delete the message block.
- mb->release ();
+ {
+ // Extract future rep from the message block.
+ future_rep =
+ ACE_reinterpret_cast (FUTURE_REP *,
+ mb->base ());
+
+ // Delete the message block.
+ mb->release ();
+ }
else
return 0;
- // Remove all nodes containing the specified future from our list.
- int count = 0;
- FUTURE_NODE *node = 0;
+ // Remove the hash map entry with the specified future rep from our map.
+ FUTURE_REP_HASH_ADDR future_rep_hash_addr (future_rep);
+ FUTURE_HOLDER *future_holder;
- for (FUTURE_LIST::ITERATOR iter (this->future_list_);
- (node = iter.next ()) != 0;
- iter.advance ())
+ if (this->future_map_.find (future_rep_hash_addr,
+ future_holder) != -1)
{
- ++count;
- if (node->item_.ready ())
- {
- future = node->item_;
- this->future_list_.remove (node);
- delete node;
-
- // NOTE: if the user inserted the same future into the list
- // more than once, then maybe I should loop through the
- // remaining futures in the list and remove all of those
- // futures which are equal to the one we are returning.
- return 1;
- }
+ future = future_holder->item_;
+ this->future_map_.unbind (future_rep_hash_addr);
+ delete future_holder;
+ return 1;
}
return 0;
@@ -126,4 +141,3 @@ ACE_Future_Set<T>::next_readable (ACE_Future<T> &future,
#endif /* ACE_HAS_THREADS */
#endif /* ACE_FUTURE_SET_CPP */
-