Re: [reSIProcate] Timers: why system time?
- From: "Alexander Altshuler" <alt@xxxxxxxxx>
- Date: Wed, 5 Nov 2008 16:32:38 +0300
Hi
Adam Roach wrote:
>You could be even more clever about it than that. Inserting a
>timer immediately before and after the rollover should get you there.
>That way, you have two timers every 49 days,
>instead of one timer every minute. :)
Here is some code to SIMULATE such timers.
And we don't need to deal with real timers.
====<8==================================================
unsigned int
BaseTimerQueue::msTillNextTimer()
{
UInt64 now;
int nextWrapAround = Timer::msTillNextWrapAroundTimer( now );
if (!mTimers.empty())
{
UInt64 next = mTimers.begin()->mWhen;
if (now > next)
{
return 0;
}
else
{
UInt64 ret64 = next - now;
if ( ret64 > UInt64(nextWrapAround) )
{
return nextWrapAround;
}
else
{
int ret = int(ret64);
return ret;
}
}
}
else
{
return nextWrapAround;
}
}
// now is returned for efficiency reason
int
Timer::msTillNextWrapAroundTimer( UInt64& now )
{
DWORD tick = ::GetTickCount();
if( ( tick > TIMER_BEGIN_SAFE_RANGE ) && ( tick <
TIMER_END_SAFE_RANGE ) )
{
LARGE_INTEGER ret;
ret.HighPart = mWrapCounter;
ret.LowPart = tick;
now = (UInt64)ret.QuadPart;
DWORD msTillNextTimer = TIMER_END_SAFE_RANGE - tick;
if( msTillNextTimer > DWORD(INT_MAX) )
{
return INT_MAX;
}
return int(msTillNextTimer);
}
Lock lock( mWrapCounterMutex );
if( mPrevTick > tick )
{
mWrapCounter++;
}
mPrevTick = tick;
LARGE_INTEGER ret;
ret.HighPart = mWrapCounter;
ret.LowPart = tick;
now = (UInt64)ret.QuadPart;
if( tick > TIMER_END_SAFE_RANGE )
{
return int( 0xffffffff - tick );
}
// tick > 0 && tick < TIMER_BEGIN_SAFE_RANGE
return INT_MAX;
}
====<8==================================================
-----Original Message-----
From: Adam Roach [mailto:adam@xxxxxxxxxxx]
Sent: Friday, October 31, 2008 10:27 PM
To: Byron Campen
Cc: Alexander; 'resiprocate-devel'
Subject: Re: [reSIProcate] Timers: why system time?
Byron Campen wrote:
> So, maybe on win32 we need to have something call getTimeMs()
> every minute? A heartbeat timer of some sort?
You could be even more clever about it than that. Inserting a timer
immediately before and after the rollover should get you there. That
way, you have two timers every 49 days, instead of one timer every
minute. :)
UInt64 timer1Time = 0x00000000FFFFFFF0ui64 | (Timer::getTimeMs() &
0xFFFFFFFF00000000ui64);
UInt64 timer2Time = timer1 + 33;
Then, all you need is a new Timer constructor that takes an absolute
time instead of a relative one.