Click to See Complete Forum and Search --> : Linux Timers add_timer init_timer compilation problem


prix
11-04-2004, 12:11 AM
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/param.h>
#include <linux/timer.h>

void showint(unsigned long i)
{
printf("%c",'.');
}

int main(void)
{
struct timer_list *tl = (struct timer_list*)malloc(sizeof(struct
timer_list));

init_timer(tl);
tl->expires = 100;
tl->function = showint;

add_timer(tl);
return 0;
}

Its basically a sample i got from some site.which i am trying to compile

I am using the following commands
gcc timer.c
and i am getting the errors
/usr/include/linux/timer.h:32: field `vec' has incomplete type
/usr/include/linux/timer.h:37: field `vec' has incomplete type
/usr/include/linux/timer.h:42: conflicting types for `typedef struct
timer_list timer_t'
/usr/include/time.h:94: previous declaration as `typedef __timer_t
timer_t'
/usr/include/linux/timer.h:63: field `list' has incomplete type
/usr/include/linux/timer.h: In function `void init_timer (timer_list
*)':
/usr/include/linux/timer.h:105: `struct timer_list' has no member named
`list'
/usr/include/linux/timer.h:105: `struct timer_list' has no member named
`list'
/usr/include/linux/timer.h: In function `int timer_pending (const
timer_list *)':
/usr/include/linux/timer.h:121: `struct timer_list' has no member named
`list'


If i compile using gcc timer.c -D__KERNEL__ -DLINUX -DMODULE -Wall -O -I/usr/include
then i get
/usr/include/linux/timer.h:42: conflicting types for `timer_t'
/usr/include/time.h:94: previous declaration of `timer_t'
kerenel is 2.4.9-34

bwkaz
11-04-2004, 09:13 PM
[code] tags and indentation are your friend. ;)

As for the errors... what happens if you change <linux/timer.h> to <time.h>? Since that's where some of these functions have already been defined, that might work.

Actually, are timer_list, init_timer, and add_timer kernel-only functions, or are they supposed to be exported to userspace? Because I don't have a manpage for any of them, and they only exist in my kernel headers (plus they're all inline there), which suggests to me that they're kernel-only. If they're kernel-only, then you can't use them in userspace programs.

There seems to be a userspace interface to them, though, in the form of POSIX timers...