1/*
2** Copyright 2002, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the OpenBeOS License.
4*/
5#ifndef KQUEUE_H
6#define KQUEUE_H
7
8/* The name "que" actually means that it is a very
9 * light-weight implementation of a queue ;-))
10 */
11
12/* The object that is put into a queue must begin with these
13 * fields, but it doesn't have to be this structure.
14 */
15struct quehead {
16	struct quehead *next;
17	struct quehead *prev;
18};
19
20/* You can use this macro to iterate through the queue. */
21#define kqueue_foreach(head, element) \
22	for ((element) = (void *)(head)->next; (element) != (void *)(head); (element) = (void *)((struct quehead *)(element))->next)
23
24
25/** Initializes a queue to be used */
26
27static inline void
28initque(void *_head)
29{
30	struct quehead *head = (struct quehead *)_head;
31
32	head->next = head->prev = head;
33}
34
35
36/** Inserts an element (_element) to the queue (_head) */
37
38static inline void
39insque(void *_element, void *_head)
40{
41	struct quehead *element = (struct quehead *)_element,
42		 *head = (struct quehead *)_head;
43
44	element->next = head->next;
45	element->prev = head;
46	head->next = element;
47	element->next->prev = element;
48}
49
50
51/** removes an element from the queue it's currently in */
52
53static inline void
54remque(void *_element)
55{
56	struct quehead *element = (struct quehead *)_element;
57
58	element->next->prev = element->prev;
59	element->prev->next = element->next;
60	element->prev = 0;
61}
62
63#endif	/* KQUEUE_H */
64