29#ifndef ETL_SCHEDULER_INCLUDED
30#define ETL_SCHEDULER_INCLUDED
52 scheduler_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
65 scheduler_no_tasks_exception(string_type file_name_, numeric_type line_number_)
78 scheduler_null_task_exception(string_type file_name_, numeric_type line_number_)
79 :
etl::scheduler_exception(ETL_ERROR_TEXT(
"scheduler:null task", ETL_SCHEDULER_FILE_ID
"B"), file_name_, line_number_)
91 scheduler_too_many_tasks_exception(string_type file_name_, numeric_type line_number_)
92 :
etl::scheduler_exception(ETL_ERROR_TEXT(
"scheduler:too many tasks", ETL_SCHEDULER_FILE_ID
"C"), file_name_, line_number_)
108 for (
size_t index = 0UL; index < task_list.
size(); ++index)
137 for (
size_t index = 0UL; index < task_list.
size(); ++index)
168 while (index < task_list.
size())
200 size_t most_index = 0UL;
201 uint32_t most_work = 0UL;
203 for (
size_t index = 0UL; index < task_list.
size(); ++index)
209 if (n_work > most_work)
219 task_list[most_index]->task_process_work();
236 virtual void start() = 0;
261 scheduler_running = scheduler_running_;
269 return scheduler_running;
277 scheduler_exit =
true;
288 if (!task_list.full())
290 typename task_list_t::iterator itask = etl::upper_bound(task_list.begin(), task_list.end(),
task.
get_task_priority(), compare_priority());
292 task_list.insert(itask, &
task);
303 template <
typename TSize>
306 for (TSize i = 0; i <
size; ++i)
319 : scheduler_running(false)
320 , scheduler_exit(false)
321 , p_idle_callback(ETL_NULLPTR)
322 , p_watchdog_callback(ETL_NULLPTR)
323 , task_list(task_list_)
327 bool scheduler_running;
337 struct compare_priority
339 bool operator()(etl::task_priority_t priority,
etl::task* ptask)
const
345 typedef etl::ivector<etl::task*> task_list_t;
346 task_list_t& task_list;
352 template <
typename TSchedulerPolicy,
size_t MAX_TASKS_>
355 ,
protected TSchedulerPolicy
361 MAX_TASKS = MAX_TASKS_,
376 scheduler_running =
true;
378 while (!scheduler_exit)
380 if (scheduler_running)
382 bool idle = TSchedulerPolicy::schedule_tasks(task_list);
384 if (p_watchdog_callback)
386 (*p_watchdog_callback)();
389 if (idle && p_idle_callback)
391 (*p_idle_callback)();
400 task_list_t task_list;
Scheduler base.
Definition scheduler.h:230
void add_task_list(etl::task **p_tasks, TSize size)
Definition scheduler.h:304
ischeduler(etl::ivector< etl::task * > &task_list_)
Constructor.
Definition scheduler.h:318
void set_watchdog_callback(etl::ifunction< void > &callback)
Set the watchdog callback.
Definition scheduler.h:251
void exit_scheduler()
Force the scheduler to exit.
Definition scheduler.h:275
void set_scheduler_running(bool scheduler_running_)
Set the running state for the scheduler.
Definition scheduler.h:259
void add_task(etl::task &task)
Definition scheduler.h:284
void set_idle_callback(etl::ifunction< void > &callback)
Set the idle callback.
Definition scheduler.h:243
bool scheduler_is_running() const
Get the running state for the scheduler.
Definition scheduler.h:267
Base exception class for scheduler.
Definition scheduler.h:49
'No tasks' exception.
Definition scheduler.h:62
'Null tasks' exception.
Definition scheduler.h:75
'Too many tasks' exception.
Definition scheduler.h:88
void start()
Start the scheduler.
Definition scheduler.h:372
Task.
Definition task.h:59
virtual void on_task_added()
Called when the task has been added to the scheduler.
Definition task.h:90
virtual uint32_t task_request_work() const =0
etl::task_priority_t get_task_priority() const
Definition task.h:115
virtual void task_process_work()=0
Called to get the task to do work.
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
Definition exception.h:59
size_type size() const
Definition vector.h:1040
bitset_ext
Definition absolute.h:40
ETL_DEPRECATED typedef scheduler_policy_sequential_multiple scheduler_policy_sequencial_multiple
Typedef for backwards compatibility with miss-spelt struct name.
Definition scheduler.h:154
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1192
ETL_DEPRECATED_REASON("Misspelt class name") typedef scheduler_policy_sequential_single scheduler_policy_sequencial_single
Typedef for backwards compatibility with miss-spelt struct name.
Definition scheduler.h:162
Definition scheduler.h:195
Definition scheduler.h:132
Definition scheduler.h:103