Ejemplo n.º 1
0
tEplKernel PUBLIC EplTimeruModifyTimerMs(tEplTimerHdl*    pTimerHdl_p,
                                        unsigned long     ulTimeMs_p,
                                        tEplTimerArg      Argument_p)
{
tEplKernel      Ret;

    Ret = EplTimeruDeleteTimer(pTimerHdl_p);
    if (Ret != kEplSuccessful)
    {
        goto Exit;
    }

    Ret = EplTimeruSetTimerMs(pTimerHdl_p, ulTimeMs_p, Argument_p);

Exit:
    return Ret;

}
tEplKernel EplTimeruModifyTimerMs(tEplTimerHdl *pTimerHdl_p,
				  unsigned long ulTime_p,
				  tEplTimerArg Argument_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplTimeruData *pData;

	// check pointer to handle
	if (pTimerHdl_p == NULL) {
		Ret = kEplTimerInvalidHandle;
		goto Exit;
	}
	// check handle itself, i.e. was the handle initialized before
	if (*pTimerHdl_p == 0) {
		Ret = EplTimeruSetTimerMs(pTimerHdl_p, ulTime_p, Argument_p);
		goto Exit;
	}
	pData = (tEplTimeruData *) * pTimerHdl_p;
	if ((tEplTimeruData *) pData->m_Timer.data != pData) {
		Ret = kEplTimerInvalidHandle;
		goto Exit;
	}

	mod_timer(&pData->m_Timer, (jiffies + ulTime_p * HZ / 1000));

	// copy the TimerArg after the timer is restarted,
	// so that a timer occured immediately before mod_timer
	// won't use the new TimerArg and
	// therefore the old timer cannot be distinguished from the new one.
	// But if the new timer is too fast, it may get lost.
	EPL_MEMCPY(&pData->TimerArgument, &Argument_p, sizeof(tEplTimerArg));

	// check if timer is really running
	if (timer_pending(&pData->m_Timer) == 0) {	// timer is not running
		// retry starting it
		add_timer(&pData->m_Timer);
	}
	// set handle to pointer of tEplTimeruData
//    *pTimerHdl_p = (tEplTimerHdl) pData;

      Exit:
	return Ret;
}