[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Future_Set.cpp
blobfceca83dd5a6438546e180c8dd0420f93dfe6c16
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)
9 #pragma once
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #if defined (ACE_HAS_THREADS)
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
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 (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 ();
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 result = this->future_map_.bind (future_rep,
69 future_holder);
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.
74 if ( result == 0 )
75 // Attach ourself to the ACE_Futures list of observer
76 future.attach (this);
77 else
78 delete future_holder;
80 return result;
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);
89 ACE_NEW (mb,
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,
98 ACE_Time_Value *tv)
100 if (this->is_empty ())
101 return 0;
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,
108 tv) != -1)
110 // Extract future rep from the message block.
111 future_rep = reinterpret_cast<FUTURE_REP *> (mb->base ());
113 // Delete the message block.
114 mb->release ();
116 else
117 return 0;
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;
127 return 1;
130 return 0;
133 ACE_END_VERSIONED_NAMESPACE_DECL
135 #endif /* ACE_HAS_THREADS */
136 #endif /* ACE_FUTURE_SET_CPP */