]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IONetworking/IOMbufQueue.h
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IONetworking / IOMbufQueue.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef _IOMBUFQUEUE_H
24 #define _IOMBUFQUEUE_H
25
26 extern "C" {
27 #include <sys/param.h>
28 #include <sys/mbuf.h>
29 }
30
31 struct IOMbufQueue {
32 struct mbuf * head;
33 struct mbuf * tail;
34 UInt32 size;
35 UInt32 capacity;
36 };
37
38 static __inline__
39 UInt32 IOMbufFree(struct mbuf * m)
40 {
41 /*LD####
42 UInt32 count = 0;
43 struct mbuf * mn;
44
45 while (( mn = m ))
46 {
47 m = mn->m_nextpkt;
48 mn->m_nextpkt = 0;
49 m_freem(mn);
50 count++;
51 }
52 return count;
53 */
54 return m_freem_list(m);
55 }
56
57 static __inline__
58 void IOMbufQueueInit(IOMbufQueue * q, UInt32 capacity)
59 {
60 q->head = q->tail = 0;
61 q->size = 0;
62 q->capacity = capacity;
63 }
64
65 static __inline__
66 bool IOMbufQueueEnqueue(IOMbufQueue * q, struct mbuf * m)
67 {
68 if (q->size >= q->capacity) return false;
69
70 if (q->size++ > 0)
71 q->tail->m_nextpkt = m;
72 else
73 q->head = m;
74
75 for (q->tail = m;
76 q->tail->m_nextpkt;
77 q->tail = q->tail->m_nextpkt, q->size++)
78 ;
79
80 return true;
81 }
82
83 static __inline__
84 bool IOMbufQueueEnqueue(IOMbufQueue * q, IOMbufQueue * qe)
85 {
86 if (qe->size)
87 {
88 if (q->size == 0)
89 q->head = qe->head;
90 else
91 q->tail->m_nextpkt = qe->head;
92 q->tail = qe->tail;
93 q->size += qe->size;
94
95 qe->head = qe->tail = 0;
96 qe->size = 0;
97 }
98 return true;
99 }
100
101 static __inline__
102 void IOMbufQueuePrepend(IOMbufQueue * q, struct mbuf * m)
103 {
104 struct mbuf * tail;
105
106 for (tail = m, q->size++;
107 tail->m_nextpkt;
108 tail = tail->m_nextpkt, q->size++)
109 ;
110
111 tail->m_nextpkt = q->head;
112 if (q->tail == 0)
113 q->tail = tail;
114 q->head = m;
115 }
116
117 static __inline__
118 void IOMbufQueuePrepend(IOMbufQueue * q, IOMbufQueue * qp)
119 {
120 if (qp->size)
121 {
122 qp->tail->m_nextpkt = q->head;
123 if (q->tail == 0)
124 q->tail = qp->tail;
125 q->head = qp->head;
126 q->size += qp->size;
127
128 qp->head = qp->tail = 0;
129 qp->size = 0;
130 }
131 }
132
133 static __inline__
134 struct mbuf * IOMbufQueueDequeue(IOMbufQueue * q)
135 {
136 struct mbuf * m = q->head;
137 if (m)
138 {
139 if ((q->head = m->m_nextpkt) == 0)
140 q->tail = 0;
141 m->m_nextpkt = 0;
142 q->size--;
143 }
144 return m;
145 }
146
147 static __inline__
148 struct mbuf * IOMbufQueueDequeueAll(IOMbufQueue * q)
149 {
150 struct mbuf * m = q->head;
151 q->head = q->tail = 0;
152 q->size = 0;
153 return m;
154 }
155
156 static __inline__
157 struct mbuf * IOMbufQueuePeek(IOMbufQueue * q)
158 {
159 return q->head;
160 }
161
162 static __inline__
163 UInt32 IOMbufQueueGetSize(IOMbufQueue * q)
164 {
165 return q->size;
166 }
167
168 static __inline__
169 UInt32 IOMbufQueueGetCapacity(IOMbufQueue * q)
170 {
171 return q->capacity;
172 }
173
174 static __inline__
175 void IOMbufQueueSetCapacity(IOMbufQueue * q, UInt32 capacity)
176 {
177 q->capacity = capacity;
178 }
179
180 #endif /* !_IOMBUFQUEUE_H */