Hi, in BSD there are two functions called timeout() and untimeout().
timeout(void (*function), void *data, unsigned long expires);
untimeout(void (* function), void *data);
where
function is the function to be called when the time is out,
data is some data structure that you will pass to the function to be called,
and expires is the time before the timer is called.
I know that in Linux, the structure that you need to use is the
struct timer_list.
And the functions to add events are add_timer(struct timer_list *),
while the function to delete timer events is del_timer(struct timer_list *).
The struct timer list is declared as follows (in linux/timer.h):
struct timer_list *next;
struct timer_list *prev;
unsigned long expires;
unsigned long data;
void (*function)(unsigned long);
My question is how do I port the BSD timeout() and untimeout() functions into
the Linux kernel code. (Or is there any simpler way to do the job?). I've
tried using the code below, it's just that I'm not sure whether that it
will work properly.
/* Linux function definition for timeout() */
void timeout( void (*function)(unsigned long),
void *data,
unsigned long expires)
{
unsigned long flags;
save_flags(flags);
cli();
data->timer.expires = expires;
data->timer.function = function(data); /* Is this valid ??? */
add_timer(timer);
restore_flags(flags);
/* Linux function definition for untimeout() */Quote:}
void untimeout(void (*function)(unsigned long), void *data)
{
unsigned long flags;
save_flags(flags);
cli();
del_timer(data->timer);
restore_flags();
Also, must I initialize the struct first by calling init_timer(structQuote:}
timer_list *) first?
Thanks for the help in advance.
Foo Chun Choong 8-)