2 * Copyright (c) 1996-1997, 2001, 2005, Juniper Networks, Inc.
4 * Jim Hayes, November 1996
6 * queue.h - Description of uKernel queues, for the Juniper Kernel
8 * JNPR: queue.h,v 1.1 2006/08/07 05:38:57 katta
16 /*---------------------------------------------------------------------------
17 * QUEUE MANAGEMENT DOCUMENTATION
27 Initialize the queue management system for the microkernel.
28 This initializes the debugging flags and sets up accounting.
36 Allocates a queue from kernel memory, and initializes it for you.
38 The default initialization provides a queue that is unbounded.
40 If you want to be bounded with special features, use q_control
43 q_alloc() returns NULL in the face of peril or low memory.
49 void *q_free(queue_t *queue_pointer)
51 Returns a queue to kernel memory, and frees the queue contents
52 for you using free() and complains (with a traceback) that you
53 tried to kill of a non-empty queue.
55 If any threads are waiting on the queue, wake them up.
60 void q_control(queue_t *queue_pointer, queue_size_t max_queue_size);
62 For now, allows you to limit queue growth.
65 Q_DEQUEUE_WAIT() ** MAY CAUSE THREAD TO BLOCK/CANNOT BE CALLED FROM ISRs **
68 void *q_dequeue_wait(queue_t *queue_pointer, wakeup_mask_t *mask)
70 Removes and returns a pointer to the next message in the specified
71 queue. If the queue is empty, the calling thread goes to sleep
72 until something is queued to the queue. If this call returns NULL,
73 then an extraordinary event requires this thread's attention--
74 check errno in this case.
77 Q_DEQUEUE ** CAN BE CALLED FROM ISRs **
80 void *q_dequeue(queue_t *queue_pointer)
82 Just like q_dequeue_wait(), but instead of blocking, return NULL.
85 Q_ENQUEUE() ** CAN BE CALLED FROM ISRs **
88 boolean q_enqueue(queue_t *queue_pointer, void *element_pointer)
90 Add the element to the end of the named queue. If the add fails
91 because a limit has been reached, return TRUE. Otherwise return
92 FALSE if everything went OK.
98 boolean q_urgent(queue_t *queue_pointer, void *element_pointer)
100 Same as q_enqueue(), except this element will be placed at the top
101 of the queue, and will be picked off at the next q_dequeue_wait()
105 Q_PEEK() ** CAN BE CALLED FROM ISRs **
108 void *q_peek(queue_t *queue_pointer)
110 Returns a pointer to the top element of the queue without actually
111 dequeuing it. Returns NULL of the queue is empty.
113 This routine will never block.
119 void q_delete(queue_t *queue_pointer, void *element_pointer)
121 Delete the element_pointer from the queue, if it exists. This
122 isn't speedy, and isn't meant for tasks requiring performance.
123 It's primary use is to pull something off the queue when you know
124 in the common case that it's gonna be at or near the top of the
125 list. (I.e. waking a thread from a wake list when extraordinary
126 conditions exist, and you have to pluck it from the middle of the
129 This routine does not block or return anything.
135 queue_size_t q_size(queue_t *queue_pointer)
137 Returns the number of elements in the queue.
143 queue_size_t q_max_size(queue_t *queue_pointer);
145 Returns the maximum size of this queue, or 0 if this queue is
150 /*-------------------------------------------------------------------------
151 * Basic queue management structures.
158 typedef u_int32_t queue_size_t;
165 queue_t *q_alloc(void);
166 void *q_peek(queue_t *queue);
167 void *q_dequeue(queue_t *queue);
168 boolean q_enqueue(queue_t *queue, void *item);
169 boolean q_urgent(queue_t *queue, void *item);
171 #endif /* __QUEUE_H__ */