2 * tqueue.h --- task queue handling for Linux.
4 * Mostly based on a proposed bottom-half replacement code written by
5 * Kai Petzke, wpp@marie.physik.tu-berlin.de.
7 * Modified for use in the Linux kernel by Theodore Ts'o,
8 * tytso@mit.edu. Any bugs are my fault, not Kai's.
10 * The original comment follows below.
13 #ifndef _LINUX_TQUEUE_H
14 #define _LINUX_TQUEUE_H
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <asm/bitops.h>
19 #include <asm/system.h>
22 * New proposed "bottom half" handlers:
23 * (C) 1994 Kai Petzke, wpp@marie.physik.tu-berlin.de
26 * - Bottom halfs are implemented as a linked list. You can have as many
27 * of them, as you want.
28 * - No more scanning of a bit field is required upon call of a bottom half.
29 * - Support for chained bottom half lists. The run_task_queue() function can be
30 * used as a bottom half handler. This is for example useful for bottom
31 * halfs, which want to be delayed until the next clock tick.
34 * - Bottom halfs are called in the reverse order that they were linked into
39 struct list_head list
; /* linked list of active bh's */
40 unsigned long sync
; /* must be initialized to zero */
41 void (*routine
)(void *); /* function to call */
42 void *data
; /* argument to function */
45 typedef struct list_head task_queue
;
47 #define DECLARE_TASK_QUEUE(q) LIST_HEAD(q)
48 #define TQ_ACTIVE(q) (!list_empty(&q))
50 extern task_queue tq_timer
, tq_immediate
, tq_disk
;
53 * To implement your own list of active bottom halfs, use the following
56 * DECLARE_TASK_QUEUE(my_bh);
57 * struct tq_struct run_my_bh = {
58 * routine: (void (*)(void *)) run_task_queue,
62 * To activate a bottom half on your list, use:
64 * queue_task(tq_pointer, &my_bh);
66 * To run the bottom halfs on your list put them on the immediate list by:
68 * queue_task(&run_my_bh, &tq_immediate);
70 * This allows you to do deferred procession. For example, you could
71 * have a bottom half list tq_timer, which is marked active by the timer
75 extern spinlock_t tqueue_lock
;
78 * Queue a task on a tq. Return non-zero if it was successfully
81 static inline int queue_task(struct tq_struct
*bh_pointer
,
85 if (!test_and_set_bit(0,&bh_pointer
->sync
)) {
87 spin_lock_irqsave(&tqueue_lock
, flags
);
88 list_add_tail(&bh_pointer
->list
, bh_list
);
89 spin_unlock_irqrestore(&tqueue_lock
, flags
);
96 * Call all "bottom halfs" on a given list.
98 static inline void run_task_queue(task_queue
*list
)
100 while (!list_empty(list
)) {
102 struct list_head
*next
;
104 spin_lock_irqsave(&tqueue_lock
, flags
);
112 p
= list_entry(next
, struct tq_struct
, list
);
116 spin_unlock_irqrestore(&tqueue_lock
, flags
);
122 spin_unlock_irqrestore(&tqueue_lock
, flags
);
126 #endif /* _LINUX_TQUEUE_H */