Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Future_Set.cpp
blobf364b486ef2eb0ae4066f47e9a2fa6e30d1b0b5a
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)
7 #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)
16 template <class T>
17 ACE_Future_Set<T>::ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *new_queue)
18 : delete_queue_ (false)
20 if (new_queue)
21 this->future_notification_queue_ = new_queue;
22 else
24 ACE_NEW (this->future_notification_queue_,
25 ACE_Message_Queue<ACE_SYNCH>);
26 this->delete_queue_ = true;
30 template <class T>
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 ();
40 for (;
41 iterator != end;
42 ++iterator)
44 FUTURE_HOLDER *future_holder = (*iterator).int_id_;
45 future_holder->item_.detach (this);
46 delete future_holder;
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),
65 -1);
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.
73 if (result == 0)
74 // Attach ourself to the ACE_Futures list of observer
75 future.attach (this);
76 else
77 delete future_holder;
79 return result;
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);
88 ACE_NEW (mb,
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,
97 ACE_Time_Value *tv)
99 if (this->is_empty ())
100 return 0;
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.
112 mb->release ();
114 else
115 return 0;
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;
124 return 1;
127 return 0;
130 ACE_END_VERSIONED_NAMESPACE_DECL
132 #endif /* ACE_HAS_THREADS */
133 #endif /* ACE_FUTURE_SET_CPP */