summaryrefslogtreecommitdiffstats
path: root/sys/mips/include/queue.h
blob: d992332c84e05907857b025a6c5b6478c62ad5f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*-
 * Copyright (c) 1996-1997, 2001, 2005, Juniper Networks, Inc.
 * All rights reserved.
 * Jim Hayes, November 1996
 *
 * queue.h - Description of uKernel queues, for the Juniper Kernel
 *
 *	JNPR: queue.h,v 1.1 2006/08/07 05:38:57 katta
 * $FreeBSD$
 *
 */

#ifndef __QUEUE_H__
#define	__QUEUE_H__

/*---------------------------------------------------------------------------
 * QUEUE MANAGEMENT DOCUMENTATION
 */

/*
   --------
   Q_INIT()
   --------

   void q_init(void)

   Initialize the queue management system for the microkernel.
   This initializes the debugging flags and sets up accounting.

   ---------
   Q_ALLOC()
   ---------

   queue_t *q_alloc()

   Allocates a queue from kernel memory, and initializes it for you.

   The default initialization provides a queue that is unbounded.

   If you want to be bounded with special features, use q_control
   after initialization.

   q_alloc() returns NULL in the face of peril or low memory.

   --------
   Q_FREE()
   --------

   void *q_free(queue_t *queue_pointer)

   Returns a queue to kernel memory, and frees the queue contents
   for you using free() and complains (with a traceback) that you
   tried to kill of a non-empty queue.

   If any threads are waiting on the queue, wake them up.

   -----------
   Q_CONTROL()
   -----------
   void q_control(queue_t *queue_pointer, queue_size_t max_queue_size);

   For now, allows you to limit queue growth.

   ----------------
   Q_DEQUEUE_WAIT() ** MAY CAUSE THREAD TO BLOCK/CANNOT BE CALLED FROM ISRs **
   ----------------

   void *q_dequeue_wait(queue_t *queue_pointer, wakeup_mask_t *mask)

   Removes and returns a pointer to the next message in the specified
   queue.  If the queue is empty, the calling thread goes to sleep
   until something is queued to the queue.  If this call returns NULL,
   then an extraordinary event requires this thread's attention--
   check errno in this case.

   ---------
   Q_DEQUEUE	 ** CAN BE CALLED FROM ISRs **
   ---------

   void *q_dequeue(queue_t *queue_pointer)

   Just like q_dequeue_wait(), but instead of blocking, return NULL.

   -----------
   Q_ENQUEUE()		   ** CAN BE CALLED FROM ISRs **
   -----------

   boolean q_enqueue(queue_t *queue_pointer, void *element_pointer)

   Add the element to the end of the named queue.  If the add fails
   because a limit has been reached, return TRUE.  Otherwise return
   FALSE if everything went OK.

   ----------
   Q_URGENT()
   ----------

   boolean q_urgent(queue_t *queue_pointer, void *element_pointer)

   Same as q_enqueue(), except this element will be placed at the top
   of the queue, and will be picked off at the next q_dequeue_wait()
   operation.

   --------
   Q_PEEK()		   ** CAN BE CALLED FROM ISRs **
   --------

   void *q_peek(queue_t *queue_pointer)

   Returns a pointer to the top element of the queue without actually
   dequeuing it.  Returns NULL of the queue is empty.

   This routine will never block.

   ----------
   Q_DELETE()
   ----------

   void q_delete(queue_t *queue_pointer, void *element_pointer)

   Delete the element_pointer from the queue, if it exists.  This
   isn't speedy, and isn't meant for tasks requiring performance.
   It's primary use is to pull something off the queue when you know
   in the common case that it's gonna be at or near the top of the
   list.  (I.e. waking a thread from a wake list when extraordinary
   conditions exist, and you have to pluck it from the middle of the
   list.)

   This routine does not block or return anything.

   --------
   Q_SIZE()
   --------

   queue_size_t q_size(queue_t *queue_pointer)

   Returns the number of elements in the queue.

   ------------
   Q_MAX_SIZE()
   ------------

   queue_size_t q_max_size(queue_t *queue_pointer);

   Returns the maximum size of this queue, or 0 if this queue is
   unbounded.

*/

/*-------------------------------------------------------------------------
 * Basic queue management structures.
 */

/*
 * Typedefs
 */

typedef u_int32_t queue_size_t;

/*
 * Prototypes
 */

void		 q_init(void);
queue_t		*q_alloc(void);
void		*q_peek(queue_t *queue);
void		*q_dequeue(queue_t *queue);
boolean		 q_enqueue(queue_t *queue, void *item);
boolean		 q_urgent(queue_t *queue, void *item);

#endif /* __QUEUE_H__ */
OpenPOWER on IntegriCloud