koyodza (15.04.2013 12:47, просмотров: 375) ответил Vladimir Ljaschko на тяжело обратно на свич-кейсы ? ;)
можно и без свич-кейсов
typedef struct tagPROCINFOSTRUCT
{
TASKHANDLE handle;
const void* pFn;
DWORD param32;
__int32 delay;
__int32 period;
//DWORD reserved[3];
}
PROCINFOSTRUCT;
///////////////////////////////////////////////////////////////////////////////
__public TASKHANDLE AddMessage(const void* pFn, DWORD param32, __int32 delay)
{
return AddProc(pFn, param32, delay, 0);
}
__public TASKHANDLE AddTask(const void* pFn, DWORD param32, __int32 delay, __int32 period)
{
return AddProc(pFn, param32, delay, period);
}
///////////////////////////////////////////////////////////////////////////////
__private void TaskExec(PROCINFOSTRUCT* p, int dTime)
{
if (p->handle.dw != TASKHANDLE_EMPTY)
{
if (p->handle.dw != TASKHANDLE_NOTREADY)
{
if (p->pFn)
{
p->delay -= dTime;
if (p->delay <= 0)
{
const void* pProc = p->pFn;
DWORD param32 = p->param32;
if (p->period > 0)
p->delay += p->period;
// else if (p->period < 0)
// p->delay = 0;
else
DeleteProcDirect(p);
pNowExec = p;
((void(*)(DWORD))(pProc))(param32);
pNowExec = NULL;
}
}
else
{
DeleteProcDirect(p);
__FAULT(1);
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
__private void DoTask(int dTime)
{
PROCINFOSTRUCT* p = procs;
for (int i = 0; i < procMax; p++, i++)
{
if (pImmediateProc)
{
PROCINFOSTRUCT* pTmp = pImmediateProc;
pImmediateProc = NULL;
TaskExec(pTmp, dTime);
}
TaskExec(p, dTime);
}
}
///////////////////////////////////////////////////////////////////////////////
__public void TaskMgr(void)
{
__int32 prevTick = sysTick;
while (sysTick < maxTime)
{
ClrWDT();
//-----------------------------------
DWORD dt = sysTick - prevTick;
if (dt)
{
prevTick += dt;
DoTask(dt);
}
//-----------------------------------
__WFI();
}
}