4 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
5 ** Distributed under the terms of the NewOS License.
13 typedef struct queue_element
{
17 typedef struct queue_typed
{
27 q
->head
= q
->tail
= NULL
;
34 queue_remove_item(queue
*_q
, void *e
)
36 queue_typed
*q
= (queue_typed
*)_q
;
37 queue_element
*elem
= (queue_element
*)e
;
38 queue_element
*temp
, *last
= NULL
;
40 temp
= (queue_element
*)q
->head
;
44 last
->next
= temp
->next
;
46 q
->head
= (queue_element
*)temp
->next
;
54 temp
= (queue_element
*)temp
->next
;
62 queue_enqueue(queue
*_q
, void *e
)
64 queue_typed
*q
= (queue_typed
*)_q
;
65 queue_element
*elem
= (queue_element
*)e
;
67 if (q
->tail
== NULL
) {
81 queue_dequeue(queue
*_q
)
83 queue_typed
*q
= (queue_typed
*)_q
;
88 q
->head
= (queue_element
*)q
->head
->next
;
107 /* fixed queue stuff */
111 fixed_queue_init(fixed_queue
*q
, int size
)
116 q
->table
= (void**)malloc(size
* sizeof(void *));
129 fixed_queue_destroy(fixed_queue
*q
)
136 fixed_queue_enqueue(fixed_queue
*q
, void *e
)
138 if (q
->count
== q
->size
)
141 q
->table
[q
->head
++] = e
;
142 if (q
->head
>= q
->size
)
151 fixed_queue_dequeue(fixed_queue
*q
)
158 e
= q
->table
[q
->tail
++];
159 if (q
->tail
>= q
->size
)
168 fixed_queue_peek(fixed_queue
*q
)
173 return q
->table
[q
->tail
];