-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.c
56 lines (44 loc) · 1.29 KB
/
timer.c
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
45
46
47
48
49
50
51
52
53
54
55
56
/* gcc -Wall -D_REENTRANT -D_POSIX_TIMERS timer.c -o timer -lrt */
#include "timer.h"
#include "ad9361-capture.h"
int timer_nr;
timer_t timer;
void timer_start (void)
{
struct sigevent sigev;
memset (&sigev, 0, sizeof (struct sigevent));
sigev.sigev_value.sival_int = timer_nr;
sigev.sigev_notify = SIGEV_THREAD;//THREAD;//SIGNAL
sigev.sigev_notify_attributes = NULL;
sigev.sigev_notify_function = tx_dirty_data;//timerxx_t;
if (timer_create (CLOCK_REALTIME, &sigev, &timer) < 0)
{
printf ("cant print anything!");
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}
}
void timer_set(void)
{
struct itimerspec itimer = { { 0, 30000000 }, { 0, 30000000 } };
if (timer_settime (timer, 0, &itimer, NULL) < 0)
{
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}
}
void timer_stop (void)
{
if (timer_delete (timer) < 0)
{
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}
}
void timerxx_t (union sigval sigval)
{
printf ("timer_nr=%02d pid=%d pthread_self=%ld\n",
sigval.sival_int, getpid (), pthread_self ());
pid_t tid = (pid_t) syscall (SYS_gettid);
printf ("in PID:[%d]TID:[%d]\n",getpid(),tid);
}