2 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 * Netatalk utility functions: queue
22 #endif /* HAVE_CONFIG_H */
26 #include <atalk/queue.h>
28 static qnode_t *alloc_init_node(void *data)
31 if ((node = malloc(sizeof(qnode_t))) == NULL)
38 /********************************************************************************
40 *******************************************************************************/
46 if ((queue = alloc_init_node(NULL)) == NULL)
49 queue->prev = queue->next = queue;
54 qnode_t *enqueue(q_t *q, void *data)
58 if ((node = alloc_init_node(data)) == NULL)
71 qnode_t *prequeue(q_t *q, void *data)
75 if ((node = alloc_init_node(data)) == NULL)
93 if (q == NULL || q->next == q)
96 /* take first node from head */
100 node->next->prev = node->prev;
106 void queue_destroy(q_t *q, void (*callback)(void *))
110 while ((p = dequeue(q)) != NULL)