2 // Copyright (c) 2010-2017 Intel Corporation
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.
28 struct rte_mbuf *entries[0];
31 static uint32_t fqueue_put(struct fqueue *q, struct rte_mbuf **mbufs, uint32_t count)
33 uint32_t free_entries = q->mask + q->cons - q->prod;
34 uint32_t beg = q->prod & q->mask;
36 count = count > free_entries? free_entries : count;
38 if ((q->prod & q->mask) + count <= q->mask) {
39 rte_memcpy(&q->entries[q->prod & q->mask], mbufs, sizeof(mbufs[0]) * count);
43 for (uint32_t i = 0; i < count; ++i) {
44 q->entries[q->prod & q->mask] = mbufs[i];
51 static uint32_t fqueue_get(struct fqueue *q, struct rte_mbuf **mbufs, uint32_t count)
53 uint32_t entries = q->prod - q->cons;
55 count = count > entries? entries : count;
57 if ((q->cons & q->mask) + count <= q->mask) {
58 rte_memcpy(mbufs, &q->entries[q->cons & q->mask], sizeof(mbufs[0]) * count);
62 for (uint32_t i = 0; i < count; ++i) {
63 mbufs[i] = q->entries[q->cons & q->mask];
70 static struct fqueue *fqueue_create(uint32_t size, int socket)
74 mem_size += sizeof(struct fqueue);
75 mem_size += sizeof(((struct fqueue *)(0))->entries[0]) * size;
77 struct fqueue *ret = prox_zmalloc(mem_size, socket);
86 #endif /* _FQUEUE_H_ */