~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/tqueue.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * tqueue.h --- task queue handling for Linux.
  3  *
  4  * Mostly based on a proposed bottom-half replacement code written by
  5  * Kai Petzke, wpp@marie.physik.tu-berlin.de.
  6  *
  7  * Modified for use in the Linux kernel by Theodore Ts'o,
  8  * tytso@mit.edu.  Any bugs are my fault, not Kai's.
  9  *
 10  * The original comment follows below.
 11  */
 12 
 13 #ifndef _LINUX_TQUEUE_H
 14 #define _LINUX_TQUEUE_H
 15 
 16 #include <linux/spinlock.h>
 17 #include <linux/list.h>
 18 #include <asm/bitops.h>
 19 #include <asm/system.h>
 20 
 21 /*
 22  * New proposed "bottom half" handlers:
 23  * (C) 1994 Kai Petzke, wpp@marie.physik.tu-berlin.de
 24  *
 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.
 32  *
 33  * Notes:
 34  * - Bottom halfs are called in the reverse order that they were linked into
 35  *   the list.
 36  */
 37 
 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 */
 43 };
 44 
 45 typedef struct list_head task_queue;
 46 
 47 #define DECLARE_TASK_QUEUE(q)   LIST_HEAD(q)
 48 #define TQ_ACTIVE(q)            (!list_empty(&q))
 49 
 50 extern task_queue tq_timer, tq_immediate, tq_disk;
 51 
 52 /*
 53  * To implement your own list of active bottom halfs, use the following
 54  * two definitions:
 55  *
 56  * DECLARE_TASK_QUEUE(my_tqueue);
 57  * struct tq_struct my_task = {
 58  *      routine: (void (*)(void *)) my_routine,
 59  *      data: &my_data
 60  * };
 61  *
 62  * To activate a bottom half on a list, use:
 63  *
 64  *      queue_task(&my_task, &my_tqueue);
 65  *
 66  * To later run the queued tasks use
 67  *
 68  *      run_task_queue(&my_tqueue);
 69  *
 70  * This allows you to do deferred processing.  For example, you could
 71  * have a task queue called tq_timer, which is executed within the timer
 72  * interrupt.
 73  */
 74 
 75 extern spinlock_t tqueue_lock;
 76 
 77 /*
 78  * Queue a task on a tq.  Return non-zero if it was successfully
 79  * added.
 80  */
 81 static inline int queue_task(struct tq_struct *bh_pointer, task_queue *bh_list)
 82 {
 83         int ret = 0;
 84         if (!test_and_set_bit(0,&bh_pointer->sync)) {
 85                 unsigned long flags;
 86                 spin_lock_irqsave(&tqueue_lock, flags);
 87                 list_add_tail(&bh_pointer->list, bh_list);
 88                 spin_unlock_irqrestore(&tqueue_lock, flags);
 89                 ret = 1;
 90         }
 91         return ret;
 92 }
 93 
 94 /*
 95  * Call all "bottom halfs" on a given list.
 96  */
 97 
 98 extern void __run_task_queue(task_queue *list);
 99 
100 static inline void run_task_queue(task_queue *list)
101 {
102         if (TQ_ACTIVE(*list))
103                 __run_task_queue(list);
104 }
105 
106 #endif /* _LINUX_TQUEUE_H */
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.