Merge pull request #2237 from DOCGroup/jwillemsen-patch-2-1
[ACE_TAO.git] / ACE / Kokyu / Kokyu_dsrt.cpp
blob65db3c552486b92b775a2baeea38754fc0170f8a
1 #include "Kokyu_dsrt.h"
3 #include "ace/Dynamic_Service.h"
4 #include "DSRT_Direct_Dispatcher_Impl_T.h"
5 #include "DSRT_CV_Dispatcher_Impl_T.h"
7 #if ! defined (__ACE_INLINE__)
8 #include "Kokyu_dsrt.inl"
9 #endif /* __ACE_INLINE__ */
11 namespace Kokyu
13 template <class DSRT_Scheduler_Traits>
14 void
15 DSRT_Dispatcher<DSRT_Scheduler_Traits>::implementation (DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>* impl)
17 std::unique_ptr<DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits> > tmp_impl (impl);
18 dispatcher_impl_ = std::move(tmp_impl);
21 template <class DSRT_Scheduler_Traits>
22 int
23 DSRT_Dispatcher<DSRT_Scheduler_Traits>::schedule (Guid_t guid, const DSRT_QoSDescriptor& qos)
25 return dispatcher_impl_->schedule (guid, qos);
28 template <class DSRT_Scheduler_Traits>
29 int
30 DSRT_Dispatcher<DSRT_Scheduler_Traits>::update_schedule (Guid_t guid, const DSRT_QoSDescriptor& qos)
32 return dispatcher_impl_->update_schedule (guid, qos);
35 template <class DSRT_Scheduler_Traits>
36 int
37 DSRT_Dispatcher<DSRT_Scheduler_Traits>::update_schedule (Guid_t guid, Kokyu::Block_Flag_t flag)
39 return dispatcher_impl_->update_schedule (guid, flag);
42 template <class DSRT_Scheduler_Traits>
43 int
44 DSRT_Dispatcher<DSRT_Scheduler_Traits>::cancel_schedule (Guid_t guid)
46 return dispatcher_impl_->cancel_schedule (guid);
49 template <class DSRT_Scheduler_Traits>
50 int DSRT_Dispatcher<DSRT_Scheduler_Traits>::shutdown ()
52 return dispatcher_impl_->shutdown ();
55 template <class DSRT_Scheduler_Traits>
56 DSRT_Dispatcher<DSRT_Scheduler_Traits>*
57 DSRT_Dispatcher_Factory<DSRT_Scheduler_Traits>::
58 create_DSRT_dispatcher (const DSRT_ConfigInfo& config_info)
60 ACE_UNUSED_ARG ((config_info));
62 DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>* tmp;
63 DSRT_Dispatcher<DSRT_Scheduler_Traits>* disp;
65 switch (config_info.impl_type_)
67 case DSRT_OS_BASED:
68 ACE_NEW_RETURN (tmp,
69 DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits> (
70 config_info.sched_policy_,
71 config_info.sched_scope_),
72 0);
73 break;
75 case DSRT_CV_BASED:
76 default:
77 ACE_NEW_RETURN (tmp,
78 DSRT_CV_Dispatcher_Impl<DSRT_Scheduler_Traits>(
79 config_info.sched_policy_,
80 config_info.sched_scope_),
81 0);
82 break;
85 ACE_ASSERT (tmp != 0);
86 ACE_NEW_RETURN (disp, DSRT_Dispatcher<DSRT_Scheduler_Traits>, 0);
87 disp->implementation (tmp);
88 tmp->init (config_info);
89 return disp;
92 template <class QoSDescriptor_t>
93 int MUF_Comparator<QoSDescriptor_t>::
94 operator ()(const QoSDescriptor_t& qos1,
95 const QoSDescriptor_t& qos2)
97 if (qos1.criticality_ > qos2.criticality_)
99 return 1;
101 else if (qos2.criticality_ > qos1.criticality_)
103 return -1;
106 typename QoSDescriptor_t::Now now_functor;
107 Time_t now = now_functor ();
109 Time_t exec_time1 = qos1.exec_time_;
110 Time_t deadline1 = qos1.deadline_;
111 Time_t laxity1 = deadline1 - now - exec_time1;
112 Time_t exec_time2 = qos2.exec_time_;
113 Time_t deadline2 = qos2.deadline_;
114 Time_t laxity2 = deadline2 - now - exec_time2;
116 if (laxity1 < laxity2)
118 return 1;
120 else if (laxity1 == laxity2)
122 return 0;
124 else
126 return -1;
130 template <class QoSDescriptor>
131 int MIF_Comparator<QoSDescriptor>::
132 operator ()(const QoSDescriptor& qos1,
133 const QoSDescriptor& qos2)
135 #ifdef KOKYU_DSRT_LOGGING
136 ACE_DEBUG ((LM_DEBUG,
137 "(%t|%T):qos1.importance = %d, qos2.importance = %d\n",
138 qos1.importance_, qos2.importance_));
139 #endif
141 if (qos1.importance_ > qos2.importance_)
143 return 1;
145 else if (qos1.importance_ == qos2.importance_)
147 return 0;
149 else
151 return -1;
155 template <class QoSDescriptor>
156 int Fixed_Priority_Comparator<QoSDescriptor>::
157 operator ()(const QoSDescriptor& qos1,
158 const QoSDescriptor& qos2)
160 if (qos1.priority_ > qos2.priority_)
162 return 1;
164 else if (qos1.priority_ == qos2.priority_)
166 return 0;
168 else
170 return -1;