Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / Kokyu / DSRT_Dispatcher_Impl_T.h
blobe56454d7ef68ca739866a792d1f72622cf58d4f3
1 /* -*- C++ -*- */
2 /**
3 * @file DSRT_Dispatcher_Impl_T.h
4 */
6 #ifndef DSRT_DISPATCHER_IMPL_H
7 #define DSRT_DISPATCHER_IMPL_H
8 #include /**/ "ace/pre.h"
10 #include "ace/Synch_Traits.h"
11 #if defined (ACE_HAS_THREADS)
12 # include "ace/Recursive_Thread_Mutex.h"
13 #else
14 # include "ace/Null_Mutex.h"
15 #endif /* ACE_HAS_THREADS */
17 #include "Kokyu_dsrt.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 namespace Kokyu
26 /**
27 * @class Comparator_Adapter_Generator
29 * @brief Generates function object adapter that adapts the
30 * QoSComparator function object to compare between two schedulable
31 * items instead of QoSDescriptors.
33 * The QoSComparator function object that gets passed through the
34 * <code> DSRT_Scheduler_Traits </code> takes two qos values and
35 * determines the more eligible one. Since the INT_ID (key) for
36 * RB_Tree needs to be of type <code> DSRT_Dispatch_Item_var
37 * </code>, the QoSComparator needs to be adapted using an adapter
38 * to compare two schedulable items. This adapter compares the two
39 * using their qos values. Ties are resolved by giving preference to
40 * items which arrived earlier. Note that this class serves the
41 * purpose of a generator class, since it generates the adapter
42 * class for a given qos comparator function object.
45 template <class DSRT_Scheduler_Traits>
46 class Comparator_Adapter_Generator
48 public:
49 typedef typename
50 DSRT_Scheduler_Traits::QoSComparator_t QoSComparator_t;
52 /**
53 * @class More_Eligible
55 * @brief Actual function object that gets generated.
57 class MoreEligible
59 public:
60 /**
61 * Function call operator to do comparison between two
62 * schedulable items. Returns 1 if item1 is more eligible than
63 * item2, otherwise 0.
65 int operator ()
66 (const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item1,
67 const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item2)
69 int rc = qos_comparator_ (item1->qos (), item2->qos ());
71 #ifdef KOKYU_DSRT_LOGGING
72 ACE_DEBUG ((LM_DEBUG,
73 "(%t|%T): MoreEligible:: qos_comparator returned %d\n",
74 rc));
75 #endif
77 //more eligible
78 if (rc == 1)
79 return rc;
81 //if equally eligible, then resolve tie with the creation time of
82 //the item
83 if (rc == 0 && item1->insertion_time () < item2->insertion_time ())
84 return 1;
86 return 0;
89 private:
90 QoSComparator_t qos_comparator_;
93 /**
94 * Facilitates return of the generated function object adapter.
96 typedef MoreEligible RET_FUNC;
99 /**
100 * @class DSRT_Dispatcher
102 * @brief Base class for DSRT dispatcher implementations
104 * The responsibility of this class is to act as a common base class
105 * for different DSRT dispatcher implementations. This is an
106 * abstract base class and cannot be instantiated.
108 template <class DSRT_Scheduler_Traits>
109 class DSRT_Dispatcher_Impl
111 public:
112 typedef typename DSRT_Scheduler_Traits::Guid_t Guid_t;
113 typedef typename DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor;
115 DSRT_Dispatcher_Impl (ACE_Sched_Params::Policy sched_policy,
116 int sched_scope);
118 /// Configure the DSRT dispatcher.
119 int init (const DSRT_ConfigInfo&);
121 /// Schedule a thread dynamically based on the qos info supplied.
122 int schedule (Guid_t guid,
123 const DSRT_QoSDescriptor&);
125 /// Update the schedule for a thread. This could alter the current
126 /// schedule.
127 int update_schedule (Guid_t guid,
128 const DSRT_QoSDescriptor&);
130 /// Inform the scheduler that the caller thread is about to
131 /// block. This could alter the current schedule.
132 int update_schedule (Guid_t guid, Block_Flag_t flag);
134 /// Cancel the schedule for a thread. This could alter the current
135 /// schedule.
136 int cancel_schedule (Guid_t guid);
138 /// Shut down the dispatcher. The dispatcher will stop processing
139 /// requests.
140 int shutdown ();
142 virtual ~DSRT_Dispatcher_Impl ();
144 private:
145 //following an idiom to avoid public virtual functions.
146 //instead make them private and use the template method
147 //pattern - "Virtually Yours" article in CUJ Experts Forum
149 virtual int init_i (const DSRT_ConfigInfo&)=0;
150 virtual int schedule_i (Guid_t guid,
151 const DSRT_QoSDescriptor&)=0;
152 virtual int update_schedule_i (Guid_t guid,
153 const DSRT_QoSDescriptor&)=0;
154 virtual int update_schedule_i (Guid_t guid, Block_Flag_t flag)=0;
155 virtual int cancel_schedule_i (Guid_t guid)=0;
156 virtual int shutdown_i ()=0;
158 protected:
159 /// Generate the QoSComparator adapter.
160 typedef typename
161 Comparator_Adapter_Generator<DSRT_Scheduler_Traits>::RET_FUNC
162 Queue_Item_Comparator_t;
164 typedef Sched_Ready_Queue<DSRT_Scheduler_Traits,
165 Queue_Item_Comparator_t,
166 ACE_SYNCH_NULL_MUTEX>
167 DSRT_Sched_Queue_t;
169 ACE_Sched_Params::Policy sched_policy_;
170 int sched_scope_;
172 Priority_t min_prio_;
173 Priority_t max_prio_;
174 Priority_t executive_prio_;
175 Priority_t blocked_prio_;
176 Priority_t inactive_prio_;
177 Priority_t active_prio_;
179 DSRT_Sched_Queue_t ready_queue_;
180 int shutdown_flagged_;
181 long non_rt_thr_flags_;
182 long rt_thr_flags_;
184 ACE_SYNCH_RECURSIVE_MUTEX synch_lock_;
186 ACE_hthread_t curr_scheduled_thr_handle_;
187 Guid_t curr_scheduled_guid_;
189 } //end of namespace
191 #if defined (__ACE_INLINE__)
192 #include "DSRT_Dispatcher_Impl_T.inl"
193 #endif /* __ACE_INLINE__ */
195 #include "DSRT_Dispatcher_Impl_T.cpp"
197 #include /**/ "ace/post.h"
198 #endif /* DSRT_DISPATCHER_IMPL_H */