1 #ifndef ACE_FUTURE_SET_CPP
2 #define ACE_FUTURE_SET_CPP
4 #include "ace/Future_Set.h"
6 #if !defined (ACE_LACKS_PRAGMA_ONCE)
8 #endif /* ACE_LACKS_PRAGMA_ONCE */
10 #if defined (ACE_HAS_THREADS)
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Future_Set
)
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 ()
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 const result
= this->future_map_
.bind (future_rep
, future_holder
);
70 // If a new map entry was created, then attach to the future,
71 // otherwise we were already attached to the future or some error
72 // occurred so just delete the future holder.
74 // Attach ourself to the ACE_Futures list of observer
82 template <class T
> void
83 ACE_Future_Set
<T
>::update (const ACE_Future
<T
> &future
)
85 ACE_Message_Block
*mb
= nullptr;
86 FUTURE
&local_future
= const_cast<ACE_Future
<T
> &> (future
);
89 ACE_Message_Block ((char *) local_future
.get_rep (), 0));
91 // Enqueue in priority order.
92 this->future_notification_queue_
->enqueue (mb
, 0);
95 template <class T
> int
96 ACE_Future_Set
<T
>::next_readable (ACE_Future
<T
> &future
,
99 if (this->is_empty ())
102 ACE_Message_Block
*mb
= nullptr;
103 FUTURE_REP
*future_rep
= nullptr;
105 // Wait for a "readable future" signal from the message queue.
106 if (this->future_notification_queue_
->dequeue_head (mb
, tv
) != -1)
108 // Extract future rep from the message block.
109 future_rep
= reinterpret_cast<FUTURE_REP
*> (mb
->base ());
111 // Delete the message block.
117 // Remove the hash map entry with the specified future rep from our map.
118 FUTURE_HOLDER
*future_holder
= nullptr;
119 if (this->future_map_
.find (future_rep
, future_holder
) != -1)
121 future
= future_holder
->item_
;
122 this->future_map_
.unbind (future_rep
);
123 delete future_holder
;
130 ACE_END_VERSIONED_NAMESPACE_DECL
132 #endif /* ACE_HAS_THREADS */
133 #endif /* ACE_FUTURE_SET_CPP */