mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-13 06:12:49 -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
|
|
@ -3,12 +3,17 @@
|
|||
#define REPEAT_TEST
|
||||
|
||||
TimerTest::TimerTest()
|
||||
: demo(0)
|
||||
{
|
||||
CtrlLayout(*this, "Window title");
|
||||
|
||||
int a = AtomicInc(demo);
|
||||
ASSERT(a==1); //preload, 1 means running demo mode, 2 means a cb is executing
|
||||
|
||||
#ifdef REPEAT_TEST
|
||||
t.SetTimeCallback(-1000, THISBACK(Test), 0);
|
||||
t.SetTimeCallback(-100, THISBACK(Test), (int)this);
|
||||
#else
|
||||
PostCallback(THISBACK(Test));
|
||||
t.SetTimeCallback(0, THISBACK(Test), (int)this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -20,13 +25,41 @@ void TimerTest::Info(const String & s)
|
|||
|
||||
void TimerTest::Test()
|
||||
{
|
||||
int a = AtomicInc(demo);
|
||||
ASSERT(a==2);
|
||||
|
||||
Info("O");
|
||||
RLOG("O");
|
||||
|
||||
a = AtomicDec(demo);
|
||||
if(a<=0)
|
||||
return;
|
||||
ASSERT(a>=0);
|
||||
|
||||
#ifdef REPEAT_TEST
|
||||
#else
|
||||
t.SetTimeCallback(1000, THISBACK(Test), 0);
|
||||
t.SetTimeCallback(100, THISBACK(Test), (int)this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TimerTest::Close()
|
||||
{
|
||||
t.KillTimeCallback((int)this);
|
||||
int a = AtomicDec(demo);
|
||||
Thread::Start(THISBACK(Close0));
|
||||
}
|
||||
|
||||
void TimerTest::Close0()
|
||||
{
|
||||
while(AtomicRead(demo) > 0) Sleep(1);
|
||||
ASSERT(AtomicRead(demo)==0);
|
||||
TopWindow::Close();
|
||||
}
|
||||
|
||||
TimerTest::~TimerTest()
|
||||
{
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TimerTest().Run();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue