2 * Copyright (c) 2016 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <rte_errno.h>
17 #include <rte_malloc.h>
19 #include <tle_event.h>
24 tle_evq_create(const struct tle_evq_param *prm)
35 sz = sizeof(*evq) + sizeof(evq->events[0]) * prm->max_events;
36 evq = rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE,
39 UDP_LOG(ERR, "allocation of %zu bytes for "
40 "new tle_evq(%u) on socket %d failed\n",
41 sz, prm->max_events, prm->socket_id);
45 TAILQ_INIT(&evq->armed);
46 TAILQ_INIT(&evq->free);
48 for (i = 0; i != prm->max_events; i++) {
49 evq->events[i].head = evq;
50 TAILQ_INSERT_TAIL(&evq->free, evq->events + i, ql);
60 tle_evq_destroy(struct tle_evq *evq)
66 tle_event_alloc(struct tle_evq *evq, const void *data)
75 rte_spinlock_lock(&evq->lock);
76 h = TAILQ_FIRST(&evq->free);
78 TAILQ_REMOVE(&evq->free, h, ql);
83 rte_spinlock_unlock(&evq->lock);
88 tle_event_free(struct tle_event *ev)
98 rte_spinlock_lock(&q->lock);
100 ev->state = TLE_SEV_IDLE;
101 TAILQ_INSERT_HEAD(&q->free, ev, ql);
103 rte_spinlock_unlock(&q->lock);