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
|
/*
* (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*/
#include <event.h>
#include "timer.h"
void *nft_timer_data(struct nft_timer *timer)
{
return timer->data;
}
static void nft_timer_callback(int fd, short mask, void *data)
{
struct nft_timer *timer = data;
timer->callback(timer);
}
void nft_timer_setup(struct nft_timer *timer, void (*cb)(struct nft_timer *),
void *data)
{
// assert: evtimer_pending(timer->event, NULL) == 0;
timer->callback = cb;
}
void nft_timer_add(struct nft_timer *timer, unsigned int sec,
unsigned int usec)
{
struct timeval tv = {
.tv_sec = sec,
.tv_usec = usec,
};
if (evtimer_pending(&timer->event, NULL))
evtimer_del(&timer->event);
evtimer_set(&timer->event, nft_timer_callback, timer);
evtimer_add(&timer->event, &tv);
}
void nft_timer_del(struct nft_timer *timer)
{
evtimer_del(&timer->event);
}
|