Introduce a simple timer API....
One can use add_timer or schedule_timer to add a timer. After the timeout time has been reached the callback will be called. One can call add_time/schedule_timer and del_timer from within the callback.
This commit is contained in:
parent
6a15d37c8c
commit
1bad601135
|
@ -1,7 +1,7 @@
|
|||
AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
|
||||
|
||||
INCLUDES = $(all_includes) -I$(top_srcdir)/include
|
||||
SUBDIRS = include src
|
||||
SUBDIRS = include src tests
|
||||
|
||||
#dist-hook:
|
||||
# rm -rf `find $(distdir) -name .svn`
|
||||
|
|
|
@ -16,4 +16,10 @@ AC_CHECK_HEADERS(mISDNif.h)
|
|||
|
||||
dnl Checks for typedefs, structures and compiler characteristics
|
||||
|
||||
AC_OUTPUT(include/openbsc/Makefile include/Makefile src/Makefile Makefile)
|
||||
AC_OUTPUT(
|
||||
include/openbsc/Makefile
|
||||
include/Makefile
|
||||
src/Makefile
|
||||
tests/Makefile
|
||||
tests/timer/Makefile
|
||||
Makefile)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
SUBDIRS = timer
|
|
@ -0,0 +1,5 @@
|
|||
INCLUDES = $(all_includes) -I$(top_srcdir)/include
|
||||
bin_PROGRAMS = timer_test
|
||||
|
||||
timer_test_SOURCES = timer_test.c $(top_srcdir)/src/timer.c $(top_srcdir)/src/select.c
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openbsc/timer.h>
|
||||
#include <openbsc/select.h>
|
||||
|
||||
static void timer_fired(unsigned long data);
|
||||
|
||||
static struct timer_list timer_one = {
|
||||
.cb = timer_fired,
|
||||
.data = (void*)1,
|
||||
};
|
||||
|
||||
static struct timer_list timer_two = {
|
||||
.cb = timer_fired,
|
||||
.data = (void*)2,
|
||||
};
|
||||
|
||||
static void timer_fired(unsigned long data)
|
||||
{
|
||||
printf("Fired timer: %lu\n", data);
|
||||
|
||||
if (data == 1) {
|
||||
schedule_timer(&timer_one, 3, 0);
|
||||
del_timer(&timer_two);
|
||||
} else if (data == 2) {
|
||||
printf("Should not be fired... bug in del_timer\n");
|
||||
} else {
|
||||
printf("wtf... wrong data\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("Starting... timer\n");
|
||||
|
||||
schedule_timer(&timer_one, 3, 0);
|
||||
schedule_timer(&timer_two, 5, 0);
|
||||
|
||||
while (1) {
|
||||
bsc_select_main();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue