|
1 #include <stdio.h> |
|
2 #include <string.h> |
|
3 #include <time.h> |
|
4 #include <signal.h> |
|
5 |
|
6 |
|
7 void timer_notify(sigval_t val) |
|
8 { |
|
9 struct timespec CURRENT_TIME; |
|
10 clock_gettime(CLOCK_REALTIME, &CURRENT_TIME); |
|
11 __run(); |
|
12 } |
|
13 |
|
14 void catch_signal(int sig) |
|
15 { |
|
16 signal(SIGTERM, catch_signal); |
|
17 signal(SIGINT, catch_signal); |
|
18 printf("Got Signal %d\n",sig); |
|
19 } |
|
20 |
|
21 int main(int argc,char **argv) |
|
22 { |
|
23 timer_t timer; |
|
24 struct sigevent sigev; |
|
25 long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000); |
|
26 time_t tv_sec = common_ticktime__/1000; |
|
27 struct itimerspec timerValues; |
|
28 |
|
29 memset (&sigev, 0, sizeof (struct sigevent)); |
|
30 memset (&timerValues, 0, sizeof (struct itimerspec)); |
|
31 sigev.sigev_value.sival_int = 0; |
|
32 sigev.sigev_notify = SIGEV_THREAD; |
|
33 sigev.sigev_notify_attributes = NULL; |
|
34 sigev.sigev_notify_function = timer_notify; |
|
35 timerValues.it_value.tv_sec = tv_sec; |
|
36 timerValues.it_value.tv_nsec = tv_nsec; |
|
37 timerValues.it_interval.tv_sec = tv_sec; |
|
38 timerValues.it_interval.tv_nsec = tv_nsec; |
|
39 |
|
40 __init(); |
|
41 |
|
42 timer_create (CLOCK_REALTIME, &sigev, &timer); |
|
43 timer_settime (timer, 0, &timerValues, NULL); |
|
44 |
|
45 /* install signal handler for manual break */ |
|
46 signal(SIGTERM, catch_signal); |
|
47 signal(SIGINT, catch_signal); |
|
48 |
|
49 pause(); |
|
50 |
|
51 timer_delete (timer); |
|
52 |
|
53 __cleanup(); |
|
54 |
|
55 return 0; |
|
56 } |