2 * Copyright (c) 2008, 2009 Nicira Networks.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include "leak-checker.h"
24 static void check_queue(struct ovs_queue *q);
26 /* Initializes 'q' as an empty packet queue. */
28 queue_init(struct ovs_queue *q)
35 /* Destroys 'q' and all of the packets that it contains. */
37 queue_destroy(struct ovs_queue *q)
39 struct ofpbuf *cur, *next;
40 for (cur = q->head; cur != NULL; cur = next) {
46 /* Removes and destroys all of the packets in 'q', rendering it empty. */
48 queue_clear(struct ovs_queue *q)
54 /* Advances the first packet in 'q' from 'q->head' to 'next', which should be
55 * the second packet in the queue.
57 * The odd, unsafe interface here allows the first packet in the queue to be
58 * passed to a function for possible consumption (and destruction) and only
59 * dropped from the queue if that function actually accepts it. */
61 queue_advance_head(struct ovs_queue *q, struct ofpbuf *next)
66 if (q->head == NULL) {
72 /* Appends 'b' to the tail of 'q'. */
74 queue_push_tail(struct ovs_queue *q, struct ofpbuf *b)
77 leak_checker_claim(b);
90 /* Removes the first buffer from 'q', which must not be empty, and returns
91 * it. The caller must free the buffer (with ofpbuf_delete()) when it is no
94 queue_pop_head(struct ovs_queue *q)
96 struct ofpbuf *head = q->head;
97 queue_advance_head(q, head->next);
101 /* Checks the internal integrity of 'q'. For use in debugging. */
103 check_queue(struct ovs_queue *q UNUSED)
110 ? q->head == NULL && q->tail == NULL
111 : q->head != NULL && q->tail != NULL);
114 for (iter = q->head; iter != NULL; iter = iter->next) {
116 assert((iter->next != NULL) == (iter != q->tail));