root/kern/include/queue.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef _QUEUE_H_
   2 #define _QUEUE_H_
   3 
   4 /* 
   5  * Queue of void pointers, implemented as a ring buffer.
   6  *
   7  * Functions:
   8  *       q_create  - allocate a new queue, with initial size SIZE.
   9  *                   Returns NULL on error.
  10  *       q_preallocate - extend the queue if necessary so its size is
  11  *                   at least SIZE. Returns an error code.
  12  *       q_empty   - return true if queue is empty.
  13  *       q_addtail - add a pointer to the tail of the queue. If the queue
  14  *                   overflows, it will extend itself, but this is slow.
  15  *                   Returns an error code if the extension fails. Does not
  16  *                   fail if no extension is required.
  17  *       q_remhead - remove a pointer from the head of the queue. If the
  18  *                   queue is empty, panics.
  19  *       q_destroy - dispose of the queue.
  20  *       q_peek    - return pointer to front element, if empty returns null
  21  *       q_len     - returns the number of elements in the queue
  22  *                   (q_getsize is the maximum number of elements that
  23  *                    can be in the queue)
  24  */
  25 
  26 struct queue; /* Opaque. */
  27 
  28 struct queue *q_create(int size);
  29 int           q_preallocate(struct queue *, int size);
  30 int           q_empty(struct queue *);
  31 int           q_addtail(struct queue *, void *ptr);
  32 void         *q_remhead(struct queue *);
  33 void          q_destroy(struct queue *);
  34 void         *q_peek(struct queue *q);
  35 int           q_len(struct queue *theq);
  36 
  37 /* 
  38  * These are really intended only for debugging. Using them encodes 
  39  * knowledge of how the queue works, which is usually undesirable.
  40  *
  41  *      q_getstart - return the index of the front of the queue
  42  *      q_getend   - return the index of the back of the queue
  43  *      q_getsize  - return the current size of the queue
  44  *      q_getguy   - return queue member by index
  45  *
  46  * To iterate over the queue, do something like
  47  *      struct queue *q;
  48  *      int i;
  49  *      
  50  *      for (i=q_getstart(q); i!=q_getend(q); i=(i+1)%q_getsize(q)) {
  51  *              void *ptr = q_getguy(q, i);
  52  *                :
  53  *      }
  54  *
  55  * If you do this, synchronization is your problem.
  56  */
  57 int   q_getstart(struct queue *);
  58 int   q_getend(struct queue *);
  59 int   q_getsize(struct queue *);
  60 void *q_getguy(struct queue *, int index);
  61 
  62 #endif /* _QUEUE_H_ */

/* [<][>][^][v][top][bottom][index][help] */