2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 OVS_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));