任务调度增加进入睡眠以及退出睡眠的委托,以方便移植到RTOS上

This commit is contained in:
大石头X2 2017-02-22 11:36:03 +08:00
parent de2db57d4d
commit 63cce80167
2 changed files with 15 additions and 1 deletions

View File

@ -173,6 +173,9 @@ TaskScheduler::TaskScheduler(cstring name)
LastTrace = Sys.Ms();
_SkipSleep = false;
EnterSleep = nullptr;
ExitSleep = nullptr;
}
// 使用外部缓冲区初始化任务列表,避免频繁的堆分配
@ -353,7 +356,11 @@ INROOT void TaskScheduler::Execute(uint msMax, bool& cancel)
{
min -= now;
Sleeping = true;
Time.Sleep(min, &Sleeping);
// 通知外部,需要睡眠若干毫秒
if(EnterSleep)
EnterSleep(min);
else
Time.Sleep(min, &Sleeping);
Sleeping = false;
// 累加睡眠时间
@ -400,6 +407,9 @@ INROOT void TaskScheduler::SkipSleep()
{
_SkipSleep = true;
Sleeping = false;
// 通知外部,要求退出睡眠,恢复调度
if(ExitSleep) ExitSleep();
}
// 显示状态

View File

@ -77,6 +77,10 @@ public:
UInt64 TotalSleep; // 所有任务的总睡眠时间ms
UInt64 LastTrace; // 最后统计跟踪时间ms
typedef void (*SAction)(uint ms);
SAction EnterSleep; // 通知外部,需要睡眠若干毫秒
Func ExitSleep; // 通知外部,要求退出睡眠,恢复调度
TaskScheduler(cstring name = nullptr);
// 使用外部缓冲区初始化任务列表,避免频繁的堆分配