コード例 #1
0
void checkSwing(float div, float del){
  setDivide(div);
  setDelay(del);
  setDelayMode();
  loop();
  int cycles = divider.value*2+1;
  int time = delay.value/2+1;
  int ticks = delay.value-time;
  int i;
  for(i=0; clockIsHigh() == combinedIsHigh() && i<1000; ++i)
    toggleClock();
  BOOST_CHECK_EQUAL(i, cycles);
  BOOST_CHECK(swinger.running == true);
  BOOST_CHECK(clockIsHigh());
  callTimer(time);
  setClock(false);
  for(i=0; !combinedIsHigh() && i<1000; ++i)
    callTimer();
  BOOST_CHECK_EQUAL(i, ticks);
  for(i=0; combinedIsHigh() && i<1000; ++i)
    callTimer();
  BOOST_CHECK_EQUAL(i, time);
}
コード例 #2
0
ファイル: timer.cpp プロジェクト: OPSF/uClinux
int MprTimerService::runTimers()
{
	MprTask		*task;
	MprTimer	*tp;
	MprTimer	*next;
	MprTime		now;
	int			till, minNap, ranTimer;

	mprGetTime(&now);
	minNap = MAXINT;

	if (mpr->isExiting()) {
		return 0;
	}

	//
	//	Loop over all timers.
	//
	ranTimer = 0;
	mprLog(8, log, "runTimers: at sec %d, usec %d\n", now.sec, now.usec);
	lock();

startAgain:
	for (tp = (MprTimer*) timerList.getFirst(); tp; tp = next) {
		next = (MprTimer*) timerList.getNext(tp);
		//
		//	If our time has not come yet, continue. Calculate minNap to speed
		//	up getIdleTime.
		//
		mprAssert(tp->inUse > 0);

		if ((tp->flags & MPR_TIMER_RUNNING) || (tp->time.sec > now.sec) || 
				((tp->time.sec == now.sec) && (tp->time.usec > now.usec))) {
			till = (tp->time.sec - now.sec) * 1000 + 
				(tp->time.usec - now.usec) / 1000;
			minNap = min(till, minNap);
			continue;
		}
		//
		//	We remove the timer from the timerList -- it will be reinserted 
		//	rescheduled by the user in the callback.
		//
		timerList.remove(tp);
		tp->flags |= MPR_TIMER_RUNNING;
		ranTimer = 1;

		//	
		//	Note: the user may call dispose() on the Timer in the callback. 
		//
		if (!(tp->flags & MPR_TIMER_TASK) || 
				mpr->poolService->getMaxPoolThreads() == 0) {
			mprLog(7, log, "runTimers: callTimer directly\n");
			
			tp->inUse++;
			unlock();
			callTimer(tp);

			lock();
			if (--tp->inUse == 0 && tp->flags & MPR_TIMER_DISPOSED) {
				mprAssert(tp->getList() == 0);
				delete tp;
			}
			//
			//	Anything may have happened while we were unlocked
			//
			goto startAgain;

		} else {
			mprLog(5, log, "runTimers: creatingTask\n");
			task = new MprTask(callTimerWrapper, (void*) tp); 
			task->start();
		}
	}
	lastRanTimers = now.sec * 1000 + now.usec / 1000;
	lastIdleTime = minNap;
	unlock();
	return ranTimer;
}