Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

include/linux/timer.h

Go to the documentation of this file.
00001 #ifndef _LINUX_TIMER_H
00002 #define _LINUX_TIMER_H
00003 
00004 /*
00005  * Old-style timers. Please don't use for any new code.
00006  *
00007  * Numbering of these timers should be consecutive to minimize
00008  * processing delays. [MJ]
00009  */
00010 
00011 #define BLANK_TIMER     0       /* Console screen-saver */
00012 #define BEEP_TIMER      1       /* Console beep */
00013 #define RS_TIMER        2       /* RS-232 ports */
00014 #define SWAP_TIMER      3       /* Background pageout */
00015 #define BACKGR_TIMER    4       /* io_request background I/O */
00016 #define HD_TIMER        5       /* Old IDE driver */
00017 #define FLOPPY_TIMER    6       /* Floppy */
00018 #define QIC02_TAPE_TIMER 7      /* QIC 02 tape */
00019 #define MCD_TIMER       8       /* Mitsumi CDROM */
00020 #define GSCD_TIMER      9       /* Goldstar CDROM */
00021 #define COMTROL_TIMER   10      /* Comtrol serial */
00022 #define DIGI_TIMER      11      /* Digi serial */
00023 #define GDTH_TIMER      12      /* Ugh - gdth scsi driver */
00024 
00025 #define COPRO_TIMER     31      /* 387 timeout for buggy hardware (boot only) */
00026 
00027 struct timer_struct {
00028         unsigned long expires;
00029         void (*fn)(void);
00030 };
00031 
00032 extern unsigned long timer_active;
00033 extern struct timer_struct timer_table[32];
00034 
00035 /*
00036  * This is completely separate from the above, and is the
00037  * "new and improved" way of handling timers more dynamically.
00038  * Hopefully efficient and general enough for most things.
00039  *
00040  * The "hardcoded" timers above are still useful for well-
00041  * defined problems, but the timer-list is probably better
00042  * when you need multiple outstanding timers or similar.
00043  *
00044  * The "data" field is in case you want to use the same
00045  * timeout function for several timeouts. You can use this
00046  * to distinguish between the different invocations.
00047  */
00048 struct timer_list {
00049         struct timer_list *next; /* MUST be first element */
00050         struct timer_list *prev;
00051         unsigned long expires;
00052         unsigned long data;
00053         void (*function)(unsigned long);
00054 };
00055 
00056 extern void add_timer(struct timer_list * timer);
00057 extern int  del_timer(struct timer_list * timer);
00058 
00059 /*
00060  * mod_timer is a more efficient way to update the expire field of an
00061  * active timer (if the timer is inactive it will be activated)
00062  * mod_timer(a,b) is equivalent to del_timer(a); a->expires = b; add_timer(a)
00063  */
00064 void mod_timer(struct timer_list *timer, unsigned long expires);
00065 
00066 extern void it_real_fn(unsigned long);
00067 
00068 extern inline void init_timer(struct timer_list * timer)
00069 {
00070         timer->next = NULL;
00071         timer->prev = NULL;
00072 }
00073 
00074 extern inline int timer_pending(struct timer_list * timer)
00075 {
00076         return timer->prev != NULL;
00077 }
00078 
00079 /*
00080  *      These inlines deal with timer wrapping correctly. You are 
00081  *      strongly encouraged to use them
00082  *      1. Because people otherwise forget
00083  *      2. Because if the timer wrap changes in future you wont have to
00084  *         alter your driver code.
00085  *
00086  * Do this with "<0" and ">=0" to only test the sign of the result. A
00087  * good compiler would generate better code (and a really good compiler
00088  * wouldn't care). Gcc is currently neither.
00089  */
00090 #define time_after(a,b)         ((long)(b) - (long)(a) < 0)
00091 #define time_before(a,b)        time_after(b,a)
00092 
00093 #define time_after_eq(a,b)      ((long)(a) - (long)(b) >= 0)
00094 #define time_before_eq(a,b)     time_after_eq(b,a)
00095 
00096 #endif