netmap_mbq.c (f9790aeb8869bfcedf111517bace712b390e6cc5) netmap_mbq.c (17885a7bfde9d164e45a9833bb172215c55739f9)
1/*
1/*
2 * Copyright (C) 2013 Vincenzo Maffione. All rights reserved.
2 * Copyright (C) 2013-2014 Vincenzo Maffione. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 31 unchanged lines hidden (view full) ---

42
43
44static inline void __mbq_init(struct mbq *q)
45{
46 q->head = q->tail = NULL;
47 q->count = 0;
48}
49
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 31 unchanged lines hidden (view full) ---

42
43
44static inline void __mbq_init(struct mbq *q)
45{
46 q->head = q->tail = NULL;
47 q->count = 0;
48}
49
50
50void mbq_safe_init(struct mbq *q)
51{
52 mtx_init(&q->lock, "mbq", NULL, MTX_SPIN);
53 __mbq_init(q);
54}
55
51void mbq_safe_init(struct mbq *q)
52{
53 mtx_init(&q->lock, "mbq", NULL, MTX_SPIN);
54 __mbq_init(q);
55}
56
57
56void mbq_init(struct mbq *q)
57{
58 __mbq_init(q);
59}
60
58void mbq_init(struct mbq *q)
59{
60 __mbq_init(q);
61}
62
63
61static inline void __mbq_enqueue(struct mbq *q, struct mbuf *m)
62{
63 m->m_nextpkt = NULL;
64 if (q->tail) {
65 q->tail->m_nextpkt = m;
66 q->tail = m;
67 } else {
68 q->head = q->tail = m;
69 }
70 q->count++;
71}
72
64static inline void __mbq_enqueue(struct mbq *q, struct mbuf *m)
65{
66 m->m_nextpkt = NULL;
67 if (q->tail) {
68 q->tail->m_nextpkt = m;
69 q->tail = m;
70 } else {
71 q->head = q->tail = m;
72 }
73 q->count++;
74}
75
76
73void mbq_safe_enqueue(struct mbq *q, struct mbuf *m)
74{
75 mtx_lock(&q->lock);
76 __mbq_enqueue(q, m);
77 mtx_unlock(&q->lock);
78}
79
77void mbq_safe_enqueue(struct mbq *q, struct mbuf *m)
78{
79 mtx_lock(&q->lock);
80 __mbq_enqueue(q, m);
81 mtx_unlock(&q->lock);
82}
83
84
80void mbq_enqueue(struct mbq *q, struct mbuf *m)
81{
82 __mbq_enqueue(q, m);
83}
84
85void mbq_enqueue(struct mbq *q, struct mbuf *m)
86{
87 __mbq_enqueue(q, m);
88}
89
90
85static inline struct mbuf *__mbq_dequeue(struct mbq *q)
86{
87 struct mbuf *ret = NULL;
88
89 if (q->head) {
90 ret = q->head;
91 q->head = ret->m_nextpkt;
92 if (q->head == NULL) {
93 q->tail = NULL;
94 }
95 q->count--;
96 ret->m_nextpkt = NULL;
97 }
98
99 return ret;
100}
101
91static inline struct mbuf *__mbq_dequeue(struct mbq *q)
92{
93 struct mbuf *ret = NULL;
94
95 if (q->head) {
96 ret = q->head;
97 q->head = ret->m_nextpkt;
98 if (q->head == NULL) {
99 q->tail = NULL;
100 }
101 q->count--;
102 ret->m_nextpkt = NULL;
103 }
104
105 return ret;
106}
107
108
102struct mbuf *mbq_safe_dequeue(struct mbq *q)
103{
104 struct mbuf *ret;
105
106 mtx_lock(&q->lock);
107 ret = __mbq_dequeue(q);
108 mtx_unlock(&q->lock);
109
110 return ret;
111}
112
109struct mbuf *mbq_safe_dequeue(struct mbq *q)
110{
111 struct mbuf *ret;
112
113 mtx_lock(&q->lock);
114 ret = __mbq_dequeue(q);
115 mtx_unlock(&q->lock);
116
117 return ret;
118}
119
120
113struct mbuf *mbq_dequeue(struct mbq *q)
114{
115 return __mbq_dequeue(q);
116}
117
121struct mbuf *mbq_dequeue(struct mbq *q)
122{
123 return __mbq_dequeue(q);
124}
125
126
118/* XXX seems pointless to have a generic purge */
119static void __mbq_purge(struct mbq *q, int safe)
120{
121 struct mbuf *m;
122
123 for (;;) {
124 m = safe ? mbq_safe_dequeue(q) : mbq_dequeue(q);
125 if (m) {
126 m_freem(m);
127 } else {
128 break;
129 }
130 }
131}
132
127/* XXX seems pointless to have a generic purge */
128static void __mbq_purge(struct mbq *q, int safe)
129{
130 struct mbuf *m;
131
132 for (;;) {
133 m = safe ? mbq_safe_dequeue(q) : mbq_dequeue(q);
134 if (m) {
135 m_freem(m);
136 } else {
137 break;
138 }
139 }
140}
141
142
133void mbq_purge(struct mbq *q)
134{
135 __mbq_purge(q, 0);
136}
137
143void mbq_purge(struct mbq *q)
144{
145 __mbq_purge(q, 0);
146}
147
148
138void mbq_safe_purge(struct mbq *q)
139{
140 __mbq_purge(q, 1);
141}
142
149void mbq_safe_purge(struct mbq *q)
150{
151 __mbq_purge(q, 1);
152}
153
154
143void mbq_safe_destroy(struct mbq *q)
144{
145 mtx_destroy(&q->lock);
146}
147
148
149void mbq_destroy(struct mbq *q)
150{
151}
155void mbq_safe_destroy(struct mbq *q)
156{
157 mtx_destroy(&q->lock);
158}
159
160
161void mbq_destroy(struct mbq *q)
162{
163}
152