1693
|
1
|
|
2 #include <signal.h>
|
|
3 #include <time.h>
|
|
4 #include <sys/time.h>
|
|
5
|
|
6 #include "timer.h"
|
|
7
|
|
8 static struct itimerval it;
|
|
9 static struct sigaction sa;
|
|
10
|
|
11 timerTSigHandler timerSigHandler;
|
|
12
|
|
13 void timerSetHandler( timerTSigHandler handler )
|
|
14 { timerSigHandler=handler; }
|
|
15
|
|
16 void timerInit( void )
|
|
17 {
|
|
18 sa.sa_handler=timerSigHandler;
|
|
19 sa.sa_flags=SA_RESTART;
|
|
20 sigemptyset( &sa.sa_mask );
|
|
21 sigaction( SIGALRM,&sa,NULL );
|
|
22 it.it_interval.tv_sec=0;
|
|
23 it.it_interval.tv_usec=20000;
|
|
24 it.it_value.tv_sec=0;
|
|
25 it.it_value.tv_usec=50000;
|
|
26 setitimer( ITIMER_REAL,&it,NULL );
|
|
27 }
|
|
28
|
|
29 void timerDone( void )
|
|
30 {
|
|
31 it.it_interval.tv_sec=0;
|
|
32 it.it_interval.tv_usec=0;
|
|
33 it.it_value.tv_sec=0;
|
|
34 it.it_value.tv_usec=0;
|
|
35 setitimer( ITIMER_REAL,&it,NULL );
|
|
36 }
|
|
37
|