3 * @file DSRT_Sched_Queue_T.cpp
5 * @author Venkita Subramonian (venkita@cs.wustl.edu)
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)
13 #endif /* ACE_LACKS_PRAGMA_ONCE */
15 #if !defined (__ACE_INLINE__)
16 //#include "DSRT_Sched_Queue_T.i"
17 #endif /* __ACE_INLINE__ */
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,
30 Sched_Ready_Queue<DSRT_Scheduler_Traits,
31 More_Eligible_Comparator,
33 Guid_Hash::operator () (const Guid_t& id)
35 typename DSRT_Scheduler_Traits::Guid_Hash guid_hash;
39 template <class DSRT_Scheduler_Traits
,
40 class More_Eligible_Comparator
,
42 int Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
43 More_Eligible_Comparator
,
48 ACE_Utils::truncate_cast
<int> (
49 dispatch_items_prio_queue_
.current_size ());
52 template <class DSRT_Scheduler_Traits
,
53 class More_Eligible_Comparator
,
55 int Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
56 More_Eligible_Comparator
,
58 most_eligible (DSRT_Dispatch_Item_var
<DSRT_Scheduler_Traits
>& item
)
60 if (dispatch_items_prio_queue_
.current_size () == 0)
65 PRIO_QUEUE_ITERATOR start
= dispatch_items_prio_queue_
.begin ();
66 PRIO_QUEUE_ENTRY
&ent
= (*start
);
71 template <class DSRT_Scheduler_Traits
,
72 class More_Eligible_Comparator
,
74 int Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
75 More_Eligible_Comparator
,
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)
88 found_item
= rb_tree_node
->item ();
92 template <class DSRT_Scheduler_Traits
,
93 class More_Eligible_Comparator
,
95 int Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
96 More_Eligible_Comparator
,
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",
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
));
122 if (dispatch_items_prio_queue_
.bind (item_var
,
126 #ifdef KOKYU_DSRT_LOGGING
127 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): item bound in rbtree\n"));
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"));
145 #ifdef KOKYU_DSRT_LOGGING
146 ACE_DEBUG ((LM_DEBUG
,
147 "(%t|%T) %d found in hashmap\n", thr_handle
));
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
));
156 if (dispatch_items_prio_queue_
.bind (item_var
,
160 #ifdef KOKYU_DSRT_LOGGING
161 ACE_DEBUG ((LM_DEBUG
,
162 "(%t|%T) %d bound to rbtree\n", thr_handle
));
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"));
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
>::
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"));
210 template <class DSRT_Scheduler_Traits
,
211 class More_Eligible_Comparator
,
213 void Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
214 More_Eligible_Comparator
,
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 ();
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 ()));
243 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):##########################\n"));
246 template <class DSRT_Scheduler_Traits
,
247 class More_Eligible_Comparator
,
249 int Sched_Ready_Queue
<DSRT_Scheduler_Traits
,
250 More_Eligible_Comparator
,
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
;
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
);
278 #endif /* DSRT_SCHED_QUEUE_T_CPP */