mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-15 22:02:51 -06:00
Timer: smaller glitches with 'sleep time remainder', TimerTest: proper close / wait for Timer enabled applications example
git-svn-id: svn://ultimatepp.org/upp/trunk@2549 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
335799d2c9
commit
cd8510db6e
6 changed files with 58 additions and 13 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
Timer::Timer()
|
||||
{
|
||||
granularity = 2;
|
||||
granularity = 10;
|
||||
run = true;
|
||||
t.Run(THISBACK(TimerThread));
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ void Timer::KillTimeCallback(void *id) {
|
|||
KillTimeCallbacks(id);
|
||||
}
|
||||
|
||||
void Timer::TimerProc(dword time)
|
||||
void Timer::TimerProc(dword time, int & leftsleep)
|
||||
{
|
||||
if(IsPanicMode())
|
||||
return;
|
||||
|
|
@ -87,7 +87,7 @@ void Timer::TimerProc(dword time)
|
|||
// sTimerLock.Leave();
|
||||
// //***
|
||||
// sTimerLock.Enter();
|
||||
while(list->GetNext() != list && list->GetNext()->time < time) {
|
||||
while(list->GetNext() != list && ((leftsleep = (list->GetNext()->time - time)) <= 0)) {
|
||||
TimeEvent *e = list->GetNext();
|
||||
e->Unlink();
|
||||
if(e->delay < 0)
|
||||
|
|
@ -98,6 +98,7 @@ void Timer::TimerProc(dword time)
|
|||
delete e;
|
||||
}
|
||||
sTimerLock.Leave();
|
||||
if(leftsleep < 0) leftsleep = granularity; //if last done has been processed and no more in queue, ensure good sleep
|
||||
}
|
||||
|
||||
//SAME API AS IN Ctrl
|
||||
|
|
@ -145,9 +146,11 @@ void Timer::SetTimerGranularity(int ms)
|
|||
|
||||
void Timer::TimerThread()
|
||||
{
|
||||
int leftsleep;
|
||||
while(run)
|
||||
{
|
||||
TimerProc(GetTickCount());
|
||||
Sleep(granularity); //granularity
|
||||
leftsleep = granularity;
|
||||
TimerProc(GetTickCount(), leftsleep);
|
||||
Sleep(min(granularity, leftsleep));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue