- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / include / linux / tqueue.h
bloba0363ffa677514a80bbb00d3e29dfdfa63d37ab1
1 /*
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
25 * Advantages:
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.
33 * Notes:
34 * - Bottom halfs are called in the reverse order that they were linked into
35 * the list.
38 struct tq_struct {
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
54 * two definitions:
56 * DECLARE_TASK_QUEUE(my_bh);
57 * struct tq_struct run_my_bh = {
58 * routine: (void (*)(void *)) run_task_queue,
59 * data: &my_bh
60 * };
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
72 * interrupt.
75 extern spinlock_t tqueue_lock;
78 * Queue a task on a tq. Return non-zero if it was successfully
79 * added.
81 static inline int queue_task(struct tq_struct *bh_pointer,
82 task_queue *bh_list)
84 int ret = 0;
85 if (!test_and_set_bit(0,&bh_pointer->sync)) {
86 unsigned long flags;
87 spin_lock_irqsave(&tqueue_lock, flags);
88 list_add_tail(&bh_pointer->list, bh_list);
89 spin_unlock_irqrestore(&tqueue_lock, flags);
90 ret = 1;
92 return ret;
96 * Call all "bottom halfs" on a given list.
98 static inline void run_task_queue(task_queue *list)
100 while (!list_empty(list)) {
101 unsigned long flags;
102 struct list_head *next;
104 spin_lock_irqsave(&tqueue_lock, flags);
105 next = list->next;
106 if (next != list) {
107 void *arg;
108 void (*f) (void *);
109 struct tq_struct *p;
111 list_del(next);
112 p = list_entry(next, struct tq_struct, list);
113 arg = p->data;
114 f = p->routine;
115 p->sync = 0;
116 spin_unlock_irqrestore(&tqueue_lock, flags);
118 if (f)
119 f(arg);
120 continue;
122 spin_unlock_irqrestore(&tqueue_lock, flags);
126 #endif /* _LINUX_TQUEUE_H */