1 // $Id: Future_Set.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_FUTURE_SET_CPP
4 #define ACE_FUTURE_SET_CPP
6 #include "ace/Future_Set.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #if defined (ACE_HAS_THREADS)
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 ACE_Future_Set
<T
>::ACE_Future_Set (ACE_Message_Queue
<ACE_SYNCH
> *new_queue
)
18 : delete_queue_ (false)
21 this->future_notification_queue_
= new_queue
;
24 ACE_NEW (this->future_notification_queue_
,
25 ACE_Message_Queue
<ACE_SYNCH
>);
26 this->delete_queue_
= true;
31 ACE_Future_Set
<T
>::~ACE_Future_Set (void)
33 // Detach ourselves from all remaining futures, if any, in our map.
34 typename
FUTURE_HASH_MAP::iterator iterator
=
35 this->future_map_
.begin ();
37 typename
FUTURE_HASH_MAP::iterator end
=
38 this->future_map_
.end ();
44 FUTURE_HOLDER
*future_holder
= (*iterator
).int_id_
;
45 future_holder
->item_
.detach (this);
49 if (this->delete_queue_
)
50 delete this->future_notification_queue_
;
53 template <class T
> int
54 ACE_Future_Set
<T
>::is_empty () const
56 return (((ACE_Future_Set
<T
>*)this)->future_map_
.current_size () == 0 );
59 template <class T
> int
60 ACE_Future_Set
<T
>::insert (ACE_Future
<T
> &future
)
62 FUTURE_HOLDER
*future_holder
;
63 ACE_NEW_RETURN (future_holder
,
64 FUTURE_HOLDER (future
),
67 FUTURE_REP
*future_rep
= future
.get_rep ();
68 int result
= this->future_map_
.bind (future_rep
,
71 // If a new map entry was created, then attach to the future,
72 // otherwise we were already attached to the future or some error
73 // occurred so just delete the future holder.
75 // Attach ourself to the ACE_Futures list of observer
83 template <class T
> void
84 ACE_Future_Set
<T
>::update (const ACE_Future
<T
> &future
)
86 ACE_Message_Block
*mb
;
87 FUTURE
&local_future
= const_cast<ACE_Future
<T
> &> (future
);
90 ACE_Message_Block ((char *) local_future
.get_rep (), 0));
92 // Enqueue in priority order.
93 this->future_notification_queue_
->enqueue (mb
, 0);
96 template <class T
> int
97 ACE_Future_Set
<T
>::next_readable (ACE_Future
<T
> &future
,
100 if (this->is_empty ())
103 ACE_Message_Block
*mb
= 0;
104 FUTURE_REP
*future_rep
= 0;
106 // Wait for a "readable future" signal from the message queue.
107 if (this->future_notification_queue_
->dequeue_head (mb
,
110 // Extract future rep from the message block.
111 future_rep
= reinterpret_cast<FUTURE_REP
*> (mb
->base ());
113 // Delete the message block.
119 // Remove the hash map entry with the specified future rep from our map.
120 FUTURE_HOLDER
*future_holder
;
121 if (this->future_map_
.find (future_rep
,
122 future_holder
) != -1)
124 future
= future_holder
->item_
;
125 this->future_map_
.unbind (future_rep
);
126 delete future_holder
;
133 ACE_END_VERSIONED_NAMESPACE_DECL
135 #endif /* ACE_HAS_THREADS */
136 #endif /* ACE_FUTURE_SET_CPP */