等待句柄的WaitOne需要循环调度,测试通过
This commit is contained in:
parent
6f54299e5c
commit
d7663a4bc3
|
@ -313,7 +313,7 @@ void TaskScheduler::Execute(uint msMax, bool& cancel)
|
|||
|
||||
// 如果有最小时间,睡一会吧
|
||||
now = Sys.Ms(); // 当前时间
|
||||
if(msMax == 0xFFFFFFFF && min != UInt64_Max && min > now)
|
||||
if(/*msMax == 0xFFFFFFFF &&*/ min != UInt64_Max && min > now)
|
||||
{
|
||||
min -= now;
|
||||
//debug_printf("任务空闲休眠 %d ms \r\n", (uint)(min/1000));
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "Task.h"
|
||||
#include "Time.h"
|
||||
|
||||
#include "WaitHandle.h"
|
||||
|
||||
WaitHandle::WaitHandle()
|
||||
|
@ -9,8 +11,24 @@ WaitHandle::WaitHandle()
|
|||
bool WaitHandle::WaitOne(int ms)
|
||||
{
|
||||
auto host = Task::Scheduler();
|
||||
host->Execute(ms, Result);
|
||||
|
||||
// 实际可用时间,-1表示无限等待
|
||||
if(ms == -1) ms = 0x7FFFFFFF;
|
||||
|
||||
auto now = Sys.Ms();
|
||||
|
||||
// 如果休眠时间足够长,允许多次调度其它任务
|
||||
while(ms > 0)
|
||||
{
|
||||
// 统计这次调度的时间
|
||||
UInt64 start = now;
|
||||
|
||||
host->Execute(ms, Result);
|
||||
|
||||
now = Sys.Ms();
|
||||
ms -= (int)(now - start);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue