📄 strategy_scheduler.cpp
字号:
long
ACE_RMS_Scheduler_Strategy::dynamic_subpriority (Dispatch_Entry &entry,
RtecScheduler::Time current_time)
{
ACE_UNUSED_ARG (entry);
ACE_UNUSED_ARG (current_time);
return 0;
}
// = All tasks in a given priority level have the same dynamic
// subpriority under RMS.
int
ACE_RMS_Scheduler_Strategy::dynamic_subpriority_comp
(const Dispatch_Entry & /* first_entry */,
const Dispatch_Entry & /* second_entry */)
{
return 0;
}
// Comparison function to pass to qsort.
int
ACE_RMS_Scheduler_Strategy::sort_function (void *arg1, void *arg2)
{
return ACE_RMS_Scheduler_Strategy::instance ()->
sort_comp (** ACE_static_cast (Dispatch_Entry **, arg1),
** ACE_static_cast (Dispatch_Entry **, arg2));
}
// = Returns minimum critical priority number.
ACE_DynScheduler::Preemption_Priority
ACE_RMS_Scheduler_Strategy::minimum_critical_priority ()
{
return minimum_critical_priority_;
}
// = Provide the dispatching queue type for the given dispatch entry.
ACE_DynScheduler::Dispatching_Type
ACE_RMS_Scheduler_Strategy::dispatch_type (const Dispatch_Entry &entry)
{
ACE_UNUSED_ARG (entry);
return RtecScheduler::STATIC_DISPATCHING;
}
/////////////////////////////////////////////////////////////////////////
// class ACE_MLF_Scheduler_Strategy static data member initializations //
/////////////////////////////////////////////////////////////////////////
ACE_MLF_Scheduler_Strategy * ACE_MLF_Scheduler_Strategy::instance_ = 0;
///////////////////////////////////////////////////////
// class ACE_MLF_Scheduler_Strategy member functions //
///////////////////////////////////////////////////////
// = Returns an instance of the strategy.
ACE_MLF_Scheduler_Strategy *
ACE_MLF_Scheduler_Strategy::instance ()
{
if (0 == ACE_MLF_Scheduler_Strategy::instance_)
{
ACE_NEW_RETURN (ACE_MLF_Scheduler_Strategy::instance_,
ACE_MLF_Scheduler_Strategy, 0);
}
return ACE_MLF_Scheduler_Strategy::instance_;
}
// = Just returns 0, as all dispatch entries are of equivalent
// static priority under MLF.
int
ACE_MLF_Scheduler_Strategy::priority_comp (const Dispatch_Entry & /* first_entry */,
const Dispatch_Entry & /* second_entry */)
{
return 0;
}
// = Sorts the dispatch entry pointer array in ascending laxity order.
void
ACE_MLF_Scheduler_Strategy::sort (
Dispatch_Entry **dispatch_entries_, u_int size)
{
ACE_OS::qsort ((void *) dispatch_entries_,
size,
sizeof (Dispatch_Entry *),
(COMP_FUNC) ACE_MLF_Scheduler_Strategy::sort_function);
}
// = Default constructor.
ACE_MLF_Scheduler_Strategy::ACE_MLF_Scheduler_Strategy (
ACE_DynScheduler::Preemption_Priority /* minimum_critical_priority */)
:ACE_Scheduler_Strategy (0)
{
}
// = Virtual destructor
ACE_MLF_Scheduler_Strategy::~ACE_MLF_Scheduler_Strategy ()
{
}
// = Returns a dynamic subpriority value for the given entry and the
// current time relative to its arrival.
long
ACE_MLF_Scheduler_Strategy::dynamic_subpriority (Dispatch_Entry &entry,
RtecScheduler::Time current_time)
{
long laxity =
ACE_U64_TO_U32 (entry.deadline () - current_time -
entry.task_entry ().rt_info ()->worst_case_execution_time);
return (laxity > 0) ? LONG_MAX - laxity : laxity;
}
// = Orders two dispatch entries by ascending laxity: returns -1 if the
// first Dispatch_Entry is greater in the order, 0 if they're equivalent,
// or 1 if the second Dispatch_Entry is greater in the order.
int
ACE_MLF_Scheduler_Strategy::dynamic_subpriority_comp
(const Dispatch_Entry &first_entry,
const Dispatch_Entry &second_entry)
{
// Order by descending dynamic priority according to ascending laxity.
u_long laxity1 =
ACE_U64_TO_U32 (first_entry.deadline () - first_entry.arrival () -
first_entry.task_entry ().rt_info ()->worst_case_execution_time);
u_long laxity2 =
ACE_U64_TO_U32 (second_entry.deadline () - first_entry.arrival () -
second_entry.task_entry ().rt_info ()->worst_case_execution_time);
if (laxity1 < laxity2)
{
return -1;
}
else if (laxity1 > laxity2)
{
return 1;
}
else
{
return 0;
}
}
// = Comparison function to pass to qsort.
int
ACE_MLF_Scheduler_Strategy::sort_function (void *arg1, void *arg2)
{
return ACE_MLF_Scheduler_Strategy::instance ()->
sort_comp (** ACE_static_cast (Dispatch_Entry **, arg1),
** ACE_static_cast (Dispatch_Entry **, arg2));
}
// = Provides the dispatching queue type for the given dispatch entry.
ACE_DynScheduler::Dispatching_Type
ACE_MLF_Scheduler_Strategy::dispatch_type (const Dispatch_Entry &entry)
{
ACE_UNUSED_ARG (entry);
return RtecScheduler::LAXITY_DISPATCHING;
}
/////////////////////////////////////////////////////////////////////////
// class ACE_EDF_Scheduler_Strategy static data member initializations //
/////////////////////////////////////////////////////////////////////////
ACE_EDF_Scheduler_Strategy * ACE_EDF_Scheduler_Strategy::instance_ = 0;
///////////////////////////////////////////////////////
// class ACE_EDF_Scheduler_Strategy member functions //
///////////////////////////////////////////////////////
// = Returns an instance of the strategy.
ACE_EDF_Scheduler_Strategy *
ACE_EDF_Scheduler_Strategy::instance ()
{
if (0 == ACE_EDF_Scheduler_Strategy::instance_)
{
ACE_NEW_RETURN (ACE_EDF_Scheduler_Strategy::instance_,
ACE_EDF_Scheduler_Strategy, 0);
}
return ACE_EDF_Scheduler_Strategy::instance_;
}
// = Just returns 0, as all dispatch entries are of
// equivalent static priority under EDF.
int
ACE_EDF_Scheduler_Strategy::priority_comp (const Dispatch_Entry & /* first_entry */,
const Dispatch_Entry & /* second_entry */)
{
return 0;
}
// = Sort the dispatch entry pointer array in ascending deadline (period) order.
void
ACE_EDF_Scheduler_Strategy::sort (
Dispatch_Entry **dispatch_entries_, u_int size)
{
ACE_OS::qsort ((void *) dispatch_entries_,
size,
sizeof (Dispatch_Entry *),
(COMP_FUNC) ACE_EDF_Scheduler_Strategy::sort_function);
}
// = Default constructor.
ACE_EDF_Scheduler_Strategy::ACE_EDF_Scheduler_Strategy (
ACE_DynScheduler::Preemption_Priority /* minimum_critical_priority */)
:ACE_Scheduler_Strategy (0)
{
}
// = Virtual destructor.
ACE_EDF_Scheduler_Strategy::~ACE_EDF_Scheduler_Strategy ()
{
}
// = Returns a dynamic subpriority value for the given entry and the
// current time relative to its arrival.
long
ACE_EDF_Scheduler_Strategy::dynamic_subpriority (Dispatch_Entry &entry,
RtecScheduler::Time current_time)
{
long time_to_deadline =
ACE_U64_TO_U32 (entry.deadline () - current_time);
return (time_to_deadline > 0)
? LONG_MAX - time_to_deadline : time_to_deadline;
}
// = Orders two dispatch entries by ascending time to deadline: returns -1 if
// the first Dispatch_Entry is greater in the order, 0 if they're equivalent,
// or 1 if the second Dispatch_Entry is greater in the order.
int
ACE_EDF_Scheduler_Strategy::dynamic_subpriority_comp
(const Dispatch_Entry &first_entry,
const Dispatch_Entry &second_entry)
{
// Order by dispatchable interval (ascending).
if (first_entry.deadline () - first_entry.arrival () <
second_entry.deadline () - first_entry.arrival ())
{
return -1;
}
else if (first_entry.deadline () - first_entry.arrival () >
second_entry.deadline () - first_entry.arrival ())
{
return 1;
}
else
{
return 0;
}
}
// = Comparison function to pass to qsort.
int
ACE_EDF_Scheduler_Strategy::sort_function (void *arg1, void *arg2)
{
return ACE_EDF_Scheduler_Strategy::instance ()->
sort_comp (** ACE_static_cast (Dispatch_Entry **, arg1),
** ACE_static_cast (Dispatch_Entry **, arg2));
}
// = Provides the dispatching queue type for the given dispatch entry.
ACE_DynScheduler::Dispatching_Type
ACE_EDF_Scheduler_Strategy::dispatch_type (const Dispatch_Entry &entry)
{
ACE_UNUSED_ARG (entry);
return RtecScheduler::DEADLINE_DISPATCHING;
}
//////////////////////////////////////////////
// class ACE_Criticality_Scheduler_Strategy //
// static data member initializations //
//////////////////////////////////////////////
ACE_Criticality_Scheduler_Strategy *
ACE_Criticality_Scheduler_Strategy::instance_ = 0;
///////////////////////////////////////////////////////////////
// class ACE_Criticality_Scheduler_Strategy member functions //
///////////////////////////////////////////////////////////////
// = Returns an instance of the strategy.
ACE_Criticality_Scheduler_Strategy *
ACE_Criticality_Scheduler_Strategy::instance ()
{
if (0 == ACE_Criticality_Scheduler_Strategy::instance_)
{
ACE_NEW_RETURN (ACE_Criticality_Scheduler_Strategy::instance_,
ACE_Criticality_Scheduler_Strategy, 0);
}
return ACE_Criticality_Scheduler_Strategy::instance_;
}
// = Compares two dispatch entries by minimum period: returns -1 if the
// first Dispatch_Entry is greater in the order, 0 if they're equivalent,
// or 1 if the second Dispatch_Entry is greater in the order.
int
ACE_Criticality_Scheduler_Strategy::priority_comp (
const Dispatch_Entry &first_entry,
const Dispatch_Entry &second_entry)
{
// Order by criticality (descending).
if (first_entry.task_entry ().rt_info ()->criticality >
second_entry.task_entry ().rt_info ()->criticality)
{
return -1;
}
else if (first_entry.task_entry ().rt_info ()->criticality <
second_entry.task_entry ().rt_info ()->criticality)
{
return 1;
}
else
{
return 0; // Same priority level.
}
}
// = Sorts the dispatch entry pointer array in descending criticality order.
void
ACE_Criticality_Scheduler_Strategy::sort (
Dispatch_Entry **dispatch_entries_, u_int size)
{
ACE_OS::qsort ((void *) dispatch_entries_,
size,
sizeof (Dispatch_Entry *),
(COMP_FUNC) ACE_Criticality_Scheduler_Strategy::sort_function);
}
// = Default constructor.
ACE_Criticality_Scheduler_Strategy::ACE_Criticality_Scheduler_Strategy (
ACE_DynScheduler::Preemption_Priority minimum_critical_priority)
:ACE_Scheduler_Strategy (minimum_critical_priority)
{
}
// = Virtual destructor.
ACE_Criticality_Scheduler_Strategy::~ACE_Criticality_Scheduler_Strategy ()
{
}
// = All entries have the same dynamic subpriority value.
long
ACE_Criticality_Scheduler_Strategy::dynamic_subpriority (Dispatch_Entry &entry,
RtecScheduler::Time current_time)
{
ACE_UNUSED_ARG (entry);
ACE_UNUSED_ARG (current_time);
return 0;
}
// = All tasks in a given priority level have the same dynamic
// subpriority under this strategy.
int
ACE_Criticality_Scheduler_Strategy::dynamic_subpriority_comp
(const Dispatch_Entry & /* first_entry */,
const Dispatch_Entry & /* second_entry */)
{
return 0;
}
// = Comparison function to pass to qsort.
int
ACE_Criticality_Scheduler_Strategy::sort_function (void *arg1, void *arg2)
{
return ACE_Criticality_Scheduler_Strategy::instance ()->
sort_comp (** ACE_static_cast (Dispatch_Entry **, arg1),
** ACE_static_cast (Dispatch_Entry **, arg2));
}
// = Returns minimum critical priority number.
ACE_DynScheduler::Preemption_Priority
ACE_Criticality_Scheduler_Strategy::minimum_critical_priority ()
{
return minimum_critical_priority_;
}
// = Provides the dispatching queue type for the given dispatch entry.
ACE_DynScheduler::Dispatching_Type
ACE_Criticality_Scheduler_Strategy::dispatch_type (const Dispatch_Entry &entry)
{
ACE_UNUSED_ARG (entry);
return RtecScheduler::STATIC_DISPATCHING;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Node<Dispatch_Entry *>;
template class ACE_Unbounded_Set<Dispatch_Entry *>;
template class ACE_Unbounded_Set_Iterator<Dispatch_Entry *>;
template class ACE_Strategy_Scheduler_Factory<ACE_MUF_Scheduler_Strategy>;
template class ACE_Strategy_Scheduler_Factory<ACE_RMS_Scheduler_Strategy>;
template class ACE_Strategy_Scheduler_Factory<ACE_MLF_Scheduler_Strategy>;
template class ACE_Strategy_Scheduler_Factory<ACE_EDF_Scheduler_Strategy>;
template class ACE_Strategy_Scheduler_Factory<ACE_Criticality_Scheduler_Strategy>;
#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Node<Dispatch_Entry *>
#pragma instantiate ACE_Unbounded_Set<Dispatch_Entry *>
#pragma instantiate ACE_Unbounded_Set_Iterator<Dispatch_Entry *>
#pragma instantiate ACE_Strategy_Scheduler_Factory<ACE_MUF_Scheduler_Strategy>
#pragma instantiate ACE_Strategy_Scheduler_Factory<ACE_RMS_Scheduler_Strategy>
#pragma instantiate ACE_Strategy_Scheduler_Factory<ACE_MLF_Scheduler_Strategy>
#pragma instantiate ACE_Strategy_Scheduler_Factory<ACE_EDF_Scheduler_Strategy>
#pragma instantiate ACE_Strategy_Scheduler_Factory<ACE_Criticality_Scheduler_Strategy>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
// EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -