Tasklets |
The Tasklet Structure
Tasklets are represented by the tasklet_struct structure. Each structure represents a unique tasklet. The structure is declared in <linux/interrupt.h>:
struct tasklet_struct {
struct tasklet_struct *next; /* next tasklet in the list */
unsigned long state; /* state of the tasklet */
atomic_t count; /* reference counter */
void (*func)(unsigned long); /* tasklet handler function */
unsigned long data; /* argument to the tasklet function */
};
Using Tasklets
Declaring Your Tasklet
You can create tasklets statically or dynamically.
What option you choose depends on whether
you have (or want) a direct or indirect reference to the tasklet.
If you are going to statically create the tasklet
(and thus have a direct reference to it),
use one of two macros in <linux/interrupt.h>:
DECLARE_TASKLET(name, func, data);//the argument "name" is up to you !not
//so importent!
Writing Your Tasklet Handler
The tasklet handler must match the correct prototype:
void tasklet_handler(unsigned long data)
As with softirqs, tasklets cannot sleep. This means you cannot
use semaphores or other blocking functions in a tasklet. Tasklets
also run with all interrupts enabled, so you must take
precautions (for example, disable interrupts and obtain a lock)
if your tasklet shares data with an interrupt handler. Unlike softirqs,
however, two of the same tasklets never run concurrentlyalthough
two different tasklets can run at the same time on two different processors.
If your tasklet shares data with another tasklet or softirq, you need to use
proper locking .