29#ifndef ETL_SCHEDULER_INCLUDED
30#define ETL_SCHEDULER_INCLUDED
79 :
etl::scheduler_exception(ETL_ERROR_TEXT(
"scheduler:null task", ETL_SCHEDULER_FILE_ID
"B"), file_name_, 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)
167 while (index < task_list.
size())
199 size_t most_index = 0UL;
200 uint32_t most_work = 0UL;
202 for (
size_t index = 0UL; index < task_list.
size(); ++index)
208 if (n_work > most_work)
218 task_list[most_index]->task_process_work();
235 virtual void start() = 0;
262 scheduler_running = scheduler_running_;
270 return scheduler_running;
278 scheduler_exit =
true;
289 if (!task_list.
full())
307 template <
typename TSize>
310 for (TSize i = 0; i < size; ++i)
323 : scheduler_running(false),
324 scheduler_exit(false),
325 p_idle_callback(ETL_NULLPTR),
326 p_watchdog_callback(ETL_NULLPTR),
327 task_list(task_list_)
331 bool scheduler_running;
341 struct compare_priority
343 bool operator()(etl::task_priority_t priority,
etl::task* ptask)
const
350 task_list_t& task_list;
356 template <
typename TSchedulerPolicy,
size_t MAX_TASKS_>
363 MAX_TASKS = MAX_TASKS_,
378 scheduler_running =
true;
380 while (!scheduler_exit)
382 if (scheduler_running)
384 bool idle = TSchedulerPolicy::schedule_tasks(task_list);
386 if (p_watchdog_callback)
388 (*p_watchdog_callback)();
391 if (idle && p_idle_callback)
393 (*p_idle_callback)();
402 task_list_t task_list;
Definition: callback.h:45
Scheduler base.
Definition: scheduler.h:229
void add_task_list(etl::task **p_tasks, TSize size)
Definition: scheduler.h:308
ischeduler(etl::ivector< etl::task * > &task_list_)
Constructor.
Definition: scheduler.h:322
void set_watchdog_callback(etl::ifunction< void > &callback)
Set the watchdog callback.
Definition: scheduler.h:252
void exit_scheduler()
Force the scheduler to exit.
Definition: scheduler.h:276
void set_scheduler_running(bool scheduler_running_)
Set the running state for the scheduler.
Definition: scheduler.h:260
void add_task(etl::task &task)
Definition: scheduler.h:285
void set_idle_callback(etl::ifunction< void > &callback)
Set the idle callback.
Definition: scheduler.h:244
bool scheduler_is_running() const
Get the running state for the scheduler.
Definition: scheduler.h:268
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
Scheduler.
Definition: scheduler.h:358
void start()
Start the scheduler.
Definition: scheduler.h:374
Task.
Definition: task.h:59
virtual void on_task_added()
Called when the task has been added to the scheduler.
Definition: task.h:92
virtual uint32_t task_request_work() const =0
etl::task_priority_t get_task_priority() const
Definition: task.h:117
virtual void task_process_work()=0
Called to get the task to do work.
#define ETL_ASSERT(b, e)
Definition: error_handler.h:316
Definition: exception.h:47
Definition: function.h:73
iterator begin()
Definition: vector.h:100
iterator end()
Definition: vector.h:118
bool full() const
Definition: vector.h:977
size_type size() const
Definition: vector.h:959
iterator insert(const_iterator position, const_reference value)
Definition: vector.h:560
bitset_ext
Definition: absolute.h:38
ETL_DEPRECATED typedef scheduler_policy_sequential_multiple scheduler_policy_sequencial_multiple
Typedef for backwards compatibility with miss-spelt struct name.
Definition: scheduler.h:153
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:161
Definition: scheduler.h:194
Definition: scheduler.h:132
Definition: scheduler.h:103