/*-
* BSD LICENSE
*
- * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
TAILQ_HEAD(rte_ring_list, rte_tailq_entry);
+static struct rte_tailq_elem rte_ring_tailq = {
+ .name = RTE_TAILQ_RING_NAME,
+};
+EAL_REGISTER_TAILQ(rte_ring_tailq)
+
/* true if x is a power of 2 */
#define POWEROF2(x) ((((x)-1) & (x)) == 0)
int mz_flags = 0;
struct rte_ring_list* ring_list = NULL;
- /* check that we have an initialised tail queue */
- if ((ring_list =
- RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
- rte_errno = E_RTE_NO_TAILQ;
- return NULL;
- }
+ ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
ring_size = rte_ring_get_memsize(count);
if (ring_size < 0) {
rte_ring_init(r, name, count, flags);
te->data = (void *) r;
+ r->memzone = mz;
TAILQ_INSERT_TAIL(ring_list, te, next);
} else {
return r;
}
+/* free the ring */
+void
+rte_ring_free(struct rte_ring *r)
+{
+ struct rte_ring_list *ring_list = NULL;
+ struct rte_tailq_entry *te;
+
+ if (r == NULL)
+ return;
+
+ /*
+ * Ring was not created with rte_ring_create,
+ * therefore, there is no memzone to free.
+ */
+ if (r->memzone == NULL) {
+ RTE_LOG(ERR, RING, "Cannot free ring (not created with rte_ring_create()");
+ return;
+ }
+
+ if (rte_memzone_free(r->memzone) != 0) {
+ RTE_LOG(ERR, RING, "Cannot free memory\n");
+ return;
+ }
+
+ ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
+ rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+
+ /* find out tailq entry */
+ TAILQ_FOREACH(te, ring_list, next) {
+ if (te->data == (void *) r)
+ break;
+ }
+
+ if (te == NULL) {
+ rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+ return;
+ }
+
+ TAILQ_REMOVE(ring_list, te, next);
+
+ rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+
+ rte_free(te);
+}
+
/*
* change the high water mark. If *count* is 0, water marking is
* disabled
const struct rte_tailq_entry *te;
struct rte_ring_list *ring_list;
- /* check that we have an initialised tail queue */
- if ((ring_list =
- RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
- rte_errno = E_RTE_NO_TAILQ;
- return;
- }
+ ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
struct rte_ring *r = NULL;
struct rte_ring_list *ring_list;
- /* check that we have an initialized tail queue */
- if ((ring_list =
- RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
- rte_errno = E_RTE_NO_TAILQ;
- return NULL;
- }
+ ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);