tailq: move to dynamic tailq
[dpdk.git] / lib / librte_hash / rte_hash.c
index d02b6b4..9245716 100644 (file)
 #include <sys/queue.h>
 
 #include <rte_common.h>
-#include <rte_memory.h>         /* for definition of CACHE_LINE_SIZE */
+#include <rte_memory.h>         /* for definition of RTE_CACHE_LINE_SIZE */
 #include <rte_log.h>
 #include <rte_memcpy.h>
 #include <rte_prefetch.h>
 #include <rte_branch_prediction.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
 #include <rte_per_lcore.h>
 
 #include "rte_hash.h"
 
-
 TAILQ_HEAD(rte_hash_list, rte_tailq_entry);
 
+static struct rte_tailq_elem rte_hash_tailq = {
+       .name = "RTE_HASH",
+};
+EAL_REGISTER_TAILQ(rte_hash_tailq)
+
 /* Macro to enable/disable run-time checking of function parameters */
 #if defined(RTE_LIBRTE_HASH_DEBUG)
 #define RETURN_IF_TRUE(cond, retval) do { \
@@ -145,12 +148,7 @@ rte_hash_find_existing(const char *name)
        struct rte_tailq_entry *te;
        struct rte_hash_list *hash_list;
 
-       /* check that we have an initialised tail queue */
-       if ((hash_list =
-                       RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_HASH, rte_hash_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return NULL;
-       }
+       hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list);
 
        rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
        TAILQ_FOREACH(te, hash_list, next) {
@@ -177,12 +175,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
        char hash_name[RTE_HASH_NAMESIZE];
        struct rte_hash_list *hash_list;
 
-       /* check that we have an initialised tail queue */
-       if ((hash_list =
-            RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_HASH, rte_hash_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return NULL;
-       }
+       hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list);
 
        /* Check for valid parameters */
        if ((params == NULL) ||
@@ -206,11 +199,11 @@ rte_hash_create(const struct rte_hash_parameters *params)
                                     sizeof(hash_sig_t), SIG_BUCKET_ALIGNMENT);
        key_size =  align_size(params->key_len, KEY_ALIGNMENT);
 
-       hash_tbl_size = align_size(sizeof(struct rte_hash), CACHE_LINE_SIZE);
+       hash_tbl_size = align_size(sizeof(struct rte_hash), RTE_CACHE_LINE_SIZE);
        sig_tbl_size = align_size(num_buckets * sig_bucket_size,
-                                 CACHE_LINE_SIZE);
+                                 RTE_CACHE_LINE_SIZE);
        key_tbl_size = align_size(num_buckets * key_size *
-                                 params->bucket_entries, CACHE_LINE_SIZE);
+                                 params->bucket_entries, RTE_CACHE_LINE_SIZE);
 
        /* Total memory required for hash context */
        mem_size = hash_tbl_size + sig_tbl_size + key_tbl_size;
@@ -233,7 +226,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
        }
 
        h = (struct rte_hash *)rte_zmalloc_socket(hash_name, mem_size,
-                                          CACHE_LINE_SIZE, params->socket_id);
+                                          RTE_CACHE_LINE_SIZE, params->socket_id);
        if (h == NULL) {
                RTE_LOG(ERR, HASH, "memory allocation failed\n");
                rte_free(te);
@@ -275,12 +268,7 @@ rte_hash_free(struct rte_hash *h)
        if (h == NULL)
                return;
 
-       /* check that we have an initialised tail queue */
-       if ((hash_list =
-            RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_HASH, rte_hash_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return;
-       }
+       hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list);
 
        rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);