summaryrefslogtreecommitdiffstats
path: root/examples/ip_pipeline/swq.c
blob: 7e54a1dbfe0428e26a5ba77a40f469a465c2f75b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#include <stdlib.h>
#include <string.h>

#include <rte_string_fns.h>

#include "swq.h"

static struct swq_list swq_list;

int
swq_init(void)
{
	TAILQ_INIT(&swq_list);

	return 0;
}

struct swq *
swq_find(const char *name)
{
	struct swq *swq;

	if (name == NULL)
		return NULL;

	TAILQ_FOREACH(swq, &swq_list, node)
		if (strcmp(swq->name, name) == 0)
			return swq;

	return NULL;
}

struct swq *
swq_create(const char *name, struct swq_params *params)
{
	struct swq *swq;
	struct rte_ring *r;
	unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;

	/* Check input params */
	if ((name == NULL) ||
		swq_find(name) ||
		(params == NULL) ||
		(params->size == 0))
		return NULL;

	/* Resource create */
	r = rte_ring_create(
		name,
		params->size,
		params->cpu_id,
		flags);

	if (r == NULL)
		return NULL;

	/* Node allocation */
	swq = calloc(1, sizeof(struct swq));
	if (swq == NULL) {
		rte_ring_free(r);
		return NULL;
	}

	/* Node fill in */
	strlcpy(swq->name, name, sizeof(swq->name));
	swq->r = r;

	/* Node add to list */
	TAILQ_INSERT_TAIL(&swq_list, swq, node);

	return swq;
}