X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_hash%2Frte_hash.c;h=007ec4425af2f310fd4776a375de4d253ba1d295;hb=f831c63cbe86c3025bc9eeccd329c1d2a6275dd5;hp=13958a3a5506d24e166eefc713caa6ca4f34ff1b;hpb=1651e2166be228125287c2e00d3ce792e9a68265;p=dpdk.git diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 13958a3a55..007ec4425a 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -55,6 +55,8 @@ #include #include #include +#include +#include #include "rte_hash.h" @@ -149,10 +151,13 @@ rte_hash_find_existing(const char *name) return NULL; } + rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); TAILQ_FOREACH(h, hash_list, next) { if (strncmp(name, h->name, RTE_HASH_NAMESIZE) == 0) break; } + rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK); + if (h == NULL) rte_errno = ENOENT; return h; @@ -205,19 +210,21 @@ rte_hash_create(const struct rte_hash_parameters *params) /* Total memory required for hash context */ mem_size = hash_tbl_size + sig_tbl_size + key_tbl_size; + rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); + /* guarantee there's no existing */ TAILQ_FOREACH(h, hash_list, next) { if (strncmp(params->name, h->name, RTE_HASH_NAMESIZE) == 0) break; } if (h != NULL) - return NULL; + goto exit; - h = (struct rte_hash *)rte_zmalloc(hash_name, mem_size, - CACHE_LINE_SIZE); + h = (struct rte_hash *)rte_zmalloc_socket(hash_name, mem_size, + CACHE_LINE_SIZE, params->socket_id); if (h == NULL) { RTE_LOG(ERR, HASH, "memory allocation failed\n"); - return NULL; + goto exit; } /* Setup hash context */ @@ -237,6 +244,10 @@ rte_hash_create(const struct rte_hash_parameters *params) DEFAULT_HASH_FUNC : params->hash_func; TAILQ_INSERT_TAIL(hash_list, h, next); + +exit: + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + return h; }