]>
Dogcows Code - chaz/tint2/blob - src/util/timer.c
1 /**************************************************************************
3 * Copyright (C) 2009 Andreas.Fink (Andreas.Fink85@gmail.com)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 **************************************************************************/
18 #include <sys/timerfd.h>
24 GSList
* timer_list
= 0;
26 int install_timer(int value_sec
, int value_nsec
, int interval_sec
, int interval_nsec
, void (*_callback
)())
28 if ( value_sec
< 0 || interval_sec
< 0 )
32 struct itimerspec timer
;
33 timer
.it_value
= (struct timespec
){ .tv_sec
=value_sec
, .tv_nsec
=value_nsec
};
34 timer
.it_interval
= (struct timespec
){ .tv_sec
=interval_sec
, .tv_nsec
=interval_nsec
};
35 timer_fd
= timerfd_create(CLOCK_MONOTONIC
, 0);
36 timerfd_settime(timer_fd
, 0, &timer
, 0);
37 struct timer
* t
= malloc(sizeof(struct timer
));
39 t
->_callback
= _callback
;
40 timer_list
= g_slist_prepend(timer_list
, t
);
45 void reset_timer(int id
, int value_sec
, int value_nsec
, int interval_sec
, int interval_nsec
)
47 struct itimerspec timer
;
48 timer
.it_value
= (struct timespec
){ .tv_sec
=value_sec
, .tv_nsec
=value_nsec
};
49 timer
.it_interval
= (struct timespec
){ .tv_sec
=interval_sec
, .tv_nsec
=interval_nsec
};
50 timerfd_settime(id
, 0, &timer
, 0);
54 void uninstall_timer(int id
)
57 GSList
* timer_iter
= timer_list
;
59 struct timer
* t
= timer_iter
->data
;
61 timer_list
= g_slist_remove(timer_list
, t
);
65 timer_iter
= timer_iter
->next
;
This page took 0.038992 seconds and 4 git commands to generate.