Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / Kokyu / DSRT_Sched_Queue_T.cpp
blobf67e48d60b5500506ee7cb1a9656cab26039aa12
1 /* -*- C++ -*- */
2 /**
3 * @file DSRT_Sched_Queue_T.cpp
5 * @author Venkita Subramonian (venkita@cs.wustl.edu)
6 */
7 #ifndef DSRT_SCHED_QUEUE_T_CPP
8 #define DSRT_SCHED_QUEUE_T_CPP
10 #include "DSRT_Sched_Queue_T.h"
11 #if !defined (ACE_LACKS_PRAGMA_ONCE)
12 # pragma once
13 #endif /* ACE_LACKS_PRAGMA_ONCE */
15 #if !defined (__ACE_INLINE__)
16 //#include "DSRT_Sched_Queue_T.i"
17 #endif /* __ACE_INLINE__ */
19 namespace Kokyu
22 //@@VS: This is somehow not being recognized by MSVC, which results
23 //in a link error. For now, the definition has been moved to the .h
24 //file. Needs further investigation.
26 template <class DSRT_Scheduler_Traits,
27 class More_Eligible_Comparator,
28 class ACE_LOCK>
29 u_long
30 Sched_Ready_Queue<DSRT_Scheduler_Traits,
31 More_Eligible_Comparator,
32 ACE_LOCK>::
33 Guid_Hash::operator () (const Guid_t& id)
35 typename DSRT_Scheduler_Traits::Guid_Hash guid_hash;
36 return guid_hash(id);
39 template <class DSRT_Scheduler_Traits,
40 class More_Eligible_Comparator,
41 class ACE_LOCK>
42 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
43 More_Eligible_Comparator,
44 ACE_LOCK>::
45 current_size ()
47 return
48 ACE_Utils::truncate_cast<int> (
49 dispatch_items_prio_queue_.current_size ());
52 template <class DSRT_Scheduler_Traits,
53 class More_Eligible_Comparator,
54 class ACE_LOCK>
55 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
56 More_Eligible_Comparator,
57 ACE_LOCK>::
58 most_eligible (DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item)
60 if (dispatch_items_prio_queue_.current_size () == 0)
62 return -1;
65 PRIO_QUEUE_ITERATOR start = dispatch_items_prio_queue_.begin ();
66 PRIO_QUEUE_ENTRY &ent = (*start);
67 item = ent.item ();
68 return 0;
71 template <class DSRT_Scheduler_Traits,
72 class More_Eligible_Comparator,
73 class ACE_LOCK>
74 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
75 More_Eligible_Comparator,
76 ACE_LOCK>::
77 find (Guid_t guid,
78 DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& found_item)
80 ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1);
81 RB_Tree_Dispatch_Item_Node* rb_tree_node = 0;
83 if (dispatch_items_hash_map_.find(guid, rb_tree_node) == -1)
85 return -1;
88 found_item = rb_tree_node->item ();
89 return 0;
92 template <class DSRT_Scheduler_Traits,
93 class More_Eligible_Comparator,
94 class ACE_LOCK>
95 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
96 More_Eligible_Comparator,
97 ACE_LOCK>::
98 insert (DSRT_Dispatch_Item<DSRT_Scheduler_Traits>* item)
100 item->insertion_time (ACE_OS::gettimeofday ());
101 DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> item_var(item);
103 ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1);
105 RB_Tree_Dispatch_Item_Node* rb_tree_node;
106 Guid_t guid = item->guid ();
108 #ifdef KOKYU_DSRT_LOGGING
109 ACE_hthread_t thr_handle = item->thread_handle ();
111 ACE_DEBUG ((LM_DEBUG,
112 "(%t|%T) about to insert %d in sched queue\n",
113 thr_handle));
114 #endif
116 if (dispatch_items_hash_map_.find (guid, rb_tree_node) == -1)
118 #ifdef KOKYU_DSRT_LOGGING
119 ACE_DEBUG ((LM_DEBUG,
120 "(%t|%T) %d not found in hashmap\n", thr_handle));
121 #endif
122 if (dispatch_items_prio_queue_.bind (item_var,
123 item_var,
124 rb_tree_node) == 0)
126 #ifdef KOKYU_DSRT_LOGGING
127 ACE_DEBUG ((LM_DEBUG, "(%t|%T): item bound in rbtree\n"));
128 #endif
129 if (dispatch_items_hash_map_.bind (guid, rb_tree_node) == 0)
131 #ifdef KOKYU_DSRT_LOGGING
132 ACE_DEBUG ((LM_DEBUG, "(%t|%T): item bound in hashmap\n"));
133 ACE_DEBUG ((LM_DEBUG,
134 "<===Hash Table contents Begin===>\n"));
135 dispatch_items_hash_map_.dump ();
136 ACE_DEBUG ((LM_DEBUG,
137 "<===Hash Table contents End=====>\n"));
138 #endif
139 return 0;
143 else
145 #ifdef KOKYU_DSRT_LOGGING
146 ACE_DEBUG ((LM_DEBUG,
147 "(%t|%T) %d found in hashmap\n", thr_handle));
148 #endif
149 dispatch_items_hash_map_.unbind (guid);
150 dispatch_items_prio_queue_.unbind (rb_tree_node);
152 #ifdef KOKYU_DSRT_LOGGING
153 ACE_DEBUG ((LM_DEBUG,
154 "(%t|%T) %d removed from hashmap and rbtree\n", thr_handle));
155 #endif
156 if (dispatch_items_prio_queue_.bind (item_var,
157 item_var,
158 rb_tree_node) == 0)
160 #ifdef KOKYU_DSRT_LOGGING
161 ACE_DEBUG ((LM_DEBUG,
162 "(%t|%T) %d bound to rbtree\n", thr_handle));
163 #endif
164 if (dispatch_items_hash_map_.bind (guid, rb_tree_node) == 0)
166 #ifdef KOKYU_DSRT_LOGGING
167 ACE_DEBUG ((LM_DEBUG,
168 "(%t|%T) %d bound to hashmap\n", thr_handle));
169 ACE_DEBUG ((LM_DEBUG,
170 "<===Hash Table contents Begin===>\n"));
171 dispatch_items_hash_map_.dump ();
172 ACE_DEBUG ((LM_DEBUG,
173 "<===Hash Table contents End===>\n"));
174 #endif
175 return 0;
180 return -1;
183 template <class DSRT_Scheduler_Traits,
184 class More_Eligible_Comparator, class ACE_LOCK>
185 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
186 More_Eligible_Comparator, ACE_LOCK>::
187 remove (Guid_t guid)
189 ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1);
190 RB_Tree_Dispatch_Item_Node* rb_tree_node = 0;
192 if (dispatch_items_hash_map_.find(guid, rb_tree_node) == 0)
194 dispatch_items_hash_map_.unbind (guid);
195 dispatch_items_prio_queue_.unbind (rb_tree_node);
196 #ifdef KOKYU_DSRT_LOGGING
197 ACE_DEBUG ((LM_DEBUG,
198 "<===Hash Table contents Begin===>\n"));
199 dispatch_items_hash_map_.dump ();
200 ACE_DEBUG ((LM_DEBUG,
201 "<===Hash Table contents End===>\n"));
202 #endif
204 return 0;
207 return -1;
210 template <class DSRT_Scheduler_Traits,
211 class More_Eligible_Comparator,
212 class ACE_LOCK>
213 void Sched_Ready_Queue<DSRT_Scheduler_Traits,
214 More_Eligible_Comparator,
215 ACE_LOCK>::
216 dump ()
218 ACE_GUARD (ACE_LOCK, mon, lock_);
219 ACE_DEBUG ((LM_DEBUG, "(%t|%T):##########################\n"));
220 if (dispatch_items_prio_queue_.current_size ())
222 PRIO_QUEUE_ITERATOR end_iter = dispatch_items_prio_queue_.end ();
223 PRIO_QUEUE_ITERATOR iter;
225 iter = dispatch_items_prio_queue_.begin ();
226 while( iter != end_iter )
228 PRIO_QUEUE_ENTRY &ent = (*iter);
229 DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>
230 item_var = ent.item ();
232 int guid;
233 ACE_OS::memcpy (&guid,
234 item_var->guid ().get_buffer (),
235 item_var->guid ().length ());
237 ACE_DEBUG ((LM_DEBUG, "(%t|%T):guid %d, thr_handle = %d\n",
238 guid, item_var->thread_handle ()));
240 ++iter;
243 ACE_DEBUG ((LM_DEBUG, "(%t|%T):##########################\n"));
246 template <class DSRT_Scheduler_Traits,
247 class More_Eligible_Comparator,
248 class ACE_LOCK>
249 int Sched_Ready_Queue<DSRT_Scheduler_Traits,
250 More_Eligible_Comparator,
251 ACE_LOCK>::
252 change_prio(int old_prio, int new_prio, int policy)
254 if (dispatch_items_prio_queue_.current_size ())
256 PRIO_QUEUE_ITERATOR end_iter = dispatch_items_prio_queue_.end ();
257 PRIO_QUEUE_ITERATOR iter;
258 int prio = 0;
260 iter = dispatch_items_prio_queue_.begin ();
261 while( iter != end_iter )
263 PRIO_QUEUE_ENTRY &ent = (*iter);
264 DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>
265 item_var = ent.item ();
266 ACE_OS::thr_getprio (item_var->thread_handle (), prio);
267 if (prio==old_prio) {
268 ACE_OS::thr_setprio(item_var->thread_handle (), new_prio, policy);
270 ++iter;
273 return(0);
278 #endif /* DSRT_SCHED_QUEUE_T_CPP */