-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.c
61 lines (48 loc) · 966 Bytes
/
example.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
57
58
59
60
61
/* This is free and unencumbered software released into the public domain. */
#include <stdio.h>
#include <signal.h>
#include "pev.h"
#define TIMEOUT 500000 /* 0.5 sec */
#define PERIOD 1000000 /* 1.0 sec */
/*
* For each call, the timer is incremented with TIMEOUT
*/
static void cb(int id, void *arg)
{
int timeout = pev_timer_get(id);
printf("Hej %d\n", timeout);
pev_timer_set(id, timeout + TIMEOUT);
}
/*
* Every one second
*/
static void periodic(int timeout, void *arg)
{
puts("+++++++++");
}
static void br(int signo, void *arg)
{
pev_exit(10);
}
int main(void)
{
int id1, id2, rc;
pev_init();
pev_sig_add(SIGINT, br, NULL);
id1 = pev_timer_add(0, PERIOD, periodic, NULL);
if (id1 < 0)
return 1;
id2 = pev_timer_add(TIMEOUT, 0, cb, NULL);
if (id2 < 0)
return 1;
rc = pev_run();
pev_timer_del(id1);
pev_timer_del(id2);
return rc;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/