examples/ip_pipeline: move config files to separate directory
[dpdk.git] / lib / librte_hash / rte_hash.c
index ba827d2..67dff5b 100644 (file)
@@ -46,7 +46,6 @@
 #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 { \
@@ -93,23 +96,23 @@ TAILQ_HEAD(rte_hash_list, rte_tailq_entry);
 static inline hash_sig_t *
 get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index)
 {
-       return (hash_sig_t *)
-                       &(h->sig_tbl[bucket_index * h->sig_tbl_bucket_size]);
+       return RTE_PTR_ADD(h->sig_tbl, (bucket_index *
+                                       h->sig_tbl_bucket_size));
 }
 
 /* Returns a pointer to the first key in specified bucket. */
 static inline uint8_t *
 get_key_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index)
 {
-       return (uint8_t *) &(h->key_tbl[bucket_index * h->bucket_entries *
-                                    h->key_tbl_key_size]);
+       return RTE_PTR_ADD(h->key_tbl, (bucket_index * h->bucket_entries *
+                                       h->key_tbl_key_size));
 }
 
 /* Returns a pointer to a key at a specific position in a specified bucket. */
 static inline void *
 get_key_from_bucket(const struct rte_hash *h, uint8_t *bkt, uint32_t pos)
 {
-       return (void *) &bkt[pos * h->key_tbl_key_size];
+       return RTE_PTR_ADD(bkt, pos * h->key_tbl_key_size);
 }
 
 /* Does integer division with rounding-up of result. */
@@ -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) ||
@@ -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);