1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2019 Intel Corporation
6 #include <rte_mempool.h>
10 __stack_alloc(struct rte_mempool *mp, uint32_t flags)
12 char name[RTE_STACK_NAMESIZE];
16 ret = snprintf(name, sizeof(name),
17 RTE_MEMPOOL_MZ_FORMAT, mp->name);
18 if (ret < 0 || ret >= (int)sizeof(name)) {
19 rte_errno = ENAMETOOLONG;
23 s = rte_stack_create(name, mp->size, mp->socket_id, flags);
33 stack_alloc(struct rte_mempool *mp)
35 return __stack_alloc(mp, 0);
39 lf_stack_alloc(struct rte_mempool *mp)
41 return __stack_alloc(mp, RTE_STACK_F_LF);
45 stack_enqueue(struct rte_mempool *mp, void * const *obj_table,
48 struct rte_stack *s = mp->pool_data;
50 return rte_stack_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
54 stack_dequeue(struct rte_mempool *mp, void **obj_table,
57 struct rte_stack *s = mp->pool_data;
59 return rte_stack_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
63 stack_get_count(const struct rte_mempool *mp)
65 struct rte_stack *s = mp->pool_data;
67 return rte_stack_count(s);
71 stack_free(struct rte_mempool *mp)
73 struct rte_stack *s = mp->pool_data;
78 static struct rte_mempool_ops ops_stack = {
82 .enqueue = stack_enqueue,
83 .dequeue = stack_dequeue,
84 .get_count = stack_get_count
87 static struct rte_mempool_ops ops_lf_stack = {
89 .alloc = lf_stack_alloc,
91 .enqueue = stack_enqueue,
92 .dequeue = stack_dequeue,
93 .get_count = stack_get_count
96 RTE_MEMPOOL_REGISTER_OPS(ops_stack);
97 RTE_MEMPOOL_REGISTER_OPS(ops_lf_stack);