-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTigTimer.cxx
More file actions
45 lines (35 loc) · 783 Bytes
/
TigTimer.cxx
File metadata and controls
45 lines (35 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <sys/time.h>
#include <assert.h>
#include "TigTimer.h"
TigTimer::TigTimer(int period_msec,TimerHandler handler)
{
assert(handler != NULL);
fPeriod_msec = period_msec;
fHandler = handler;
fLastTime = GetTimeSec();
Start(period_msec,kTRUE);
}
//GetTimeSec
double
TigTimer::GetTimeSec()
{
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec + 0.000001*tv.tv_usec;
}
//---- Notify
Bool_t
TigTimer::Notify()
{
double t = GetTimeSec();
//printf("timer notify, period %f should be %f!\n",t-fLastTime,fPeriod_msec*0.001);
if (t - fLastTime >= 0.9*fPeriod_msec*0.001)
{
//printf("timer: call handler %p\n",fHandler);
if (fHandler)
(*fHandler)();
fLastTime = t;
}
Reset();
return kTRUE;
}