]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/queue.c
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / kern / queue.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * HISTORY
30 *
31 * Revision 1.1.1.1 1998/09/22 21:05:33 wsanchez
32 * Import of Mac OS X kernel (~semeria)
33 *
34 * Revision 1.1.1.1 1998/03/07 02:25:55 wsanchez
35 * Import of OSF Mach kernel (~mburg)
36 *
37 * Revision 1.1.10.3 1995/03/15 17:21:19 bruel
38 * compile only if !__GNUC__.
39 * [95/03/09 bruel]
40 *
41 * Revision 1.1.10.2 1995/01/06 19:48:05 devrcs
42 * mk6 CR668 - 1.3b26 merge
43 * * Revision 1.1.3.5 1994/05/06 18:51:43 tmt
44 * Merge in DEC Alpha changes to osc1.3b19.
45 * Merge Alpha changes into osc1.312b source code.
46 * Remove ifdef sun around insque and remque.
47 * * End1.3merge
48 * [1994/11/04 09:29:15 dwm]
49 *
50 * Revision 1.1.10.1 1994/09/23 02:25:00 ezf
51 * change marker to not FREE
52 * [1994/09/22 21:35:34 ezf]
53 *
54 * Revision 1.1.3.3 1993/07/28 17:16:26 bernard
55 * CR9523 -- Prototypes.
56 * [1993/07/21 17:00:38 bernard]
57 *
58 * Revision 1.1.3.2 1993/06/02 23:39:41 jeffc
59 * Added to OSF/1 R1.3 from NMK15.0.
60 * [1993/06/02 21:13:58 jeffc]
61 *
62 * Revision 1.1 1992/09/30 02:09:52 robert
63 * Initial revision
64 *
65 * $EndLog$
66 */
67/* CMU_HIST */
68/*
69 * Revision 2.4 91/05/14 16:45:45 mrt
70 * Correcting copyright
71 *
72 * Revision 2.3 91/05/08 12:48:22 dbg
73 * Compile queue routines on vax.
74 * [91/03/26 dbg]
75 *
76 * Revision 2.2 91/02/05 17:28:38 mrt
77 * Changed to new Mach copyright
78 * [91/02/01 16:16:22 mrt]
79 *
80 * Revision 2.1 89/08/03 15:51:47 rwd
81 * Created.
82 *
83 * 17-Mar-87 David Golub (dbg) at Carnegie-Mellon University
84 * Created from routines written by David L. Black.
85 *
86 */
87/* CMU_ENDHIST */
88/*
89 * Mach Operating System
90 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
91 * All Rights Reserved.
92 *
93 * Permission to use, copy, modify and distribute this software and its
94 * documentation is hereby granted, provided that both the copyright
95 * notice and this permission notice appear in all copies of the
96 * software, derivative works or modified versions, and any portions
97 * thereof, and that both notices appear in supporting documentation.
98 *
99 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
100 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
101 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
102 *
103 * Carnegie Mellon requests users of this software to return to
104 *
105 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
106 * School of Computer Science
107 * Carnegie Mellon University
108 * Pittsburgh PA 15213-3890
109 *
110 * any improvements or extensions that they make and grant Carnegie Mellon
111 * the rights to redistribute these changes.
112 */
113/*
114 */
115
116/*
117 * Routines to implement queue package.
118 */
119
120#include <kern/queue.h>
121
122#if !defined(__GNUC__)
123
124/*
125 * Insert element at head of queue.
126 */
127void
128enqueue_head(
129 register queue_t que,
130 register queue_entry_t elt)
131{
132 elt->next = que->next;
133 elt->prev = que;
134 elt->next->prev = elt;
135 que->next = elt;
136}
137
138/*
139 * Insert element at tail of queue.
140 */
141void
142enqueue_tail(
143 register queue_t que,
144 register queue_entry_t elt)
145{
146 elt->next = que;
147 elt->prev = que->prev;
148 elt->prev->next = elt;
149 que->prev = elt;
150}
151
152/*
153 * Remove and return element at head of queue.
154 */
155queue_entry_t
156dequeue_head(
157 register queue_t que)
158{
159 register queue_entry_t elt;
160
161 if (que->next == que)
162 return((queue_entry_t)0);
163
164 elt = que->next;
165 elt->next->prev = que;
166 que->next = elt->next;
167 return(elt);
168}
169
170/*
171 * Remove and return element at tail of queue.
172 */
173queue_entry_t
174dequeue_tail(
175 register queue_t que)
176{
177 register queue_entry_t elt;
178
179 if (que->prev == que)
180 return((queue_entry_t)0);
181
182 elt = que->prev;
183 elt->prev->next = que;
184 que->prev = elt->prev;
185 return(elt);
186}
187
188/*
189 * Remove arbitrary element from queue.
190 * Does not check whether element is on queue - the world
191 * will go haywire if it isn't.
192 */
193
194/*ARGSUSED*/
195void
196remqueue(
197 queue_t que,
198 register queue_entry_t elt)
199{
200 elt->next->prev = elt->prev;
201 elt->prev->next = elt->next;
202}
203
204/*
205 * Routines to directly imitate the VAX hardware queue
206 * package.
207 */
208void
209insque(
210 register queue_entry_t entry,
211 register queue_entry_t pred)
212{
213 entry->next = pred->next;
214 entry->prev = pred;
215 (pred->next)->prev = entry;
216 pred->next = entry;
217}
218
219int
220remque(
221 register queue_entry_t elt)
222{
223 (elt->next)->prev = elt->prev;
224 (elt->prev)->next = elt->next;
225 return((int)elt);
226}
227
228#endif