等待句柄的WaitOne需要循环调度,测试通过

This commit is contained in:
Stone 2016-06-16 08:35:40 +00:00
parent 6f54299e5c
commit d7663a4bc3
2 changed files with 20 additions and 2 deletions

View File

@ -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));

View File

@ -1,4 +1,6 @@
#include "Task.h"
#include "Time.h"
#include "WaitHandle.h"
WaitHandle::WaitHandle()
@ -9,7 +11,23 @@ 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;
}