X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Flibrte_hash%2Frte_fbk_hash.c;h=2d2b11a198c19d27844936edd139eb40d11dd7f7;hb=f831c63cbe86c3025bc9eeccd329c1d2a6275dd5;hp=4163c928c7c43faa7292c1694c82d9e9e9829ecb;hpb=34258ce5db7a3cb997fc774b02d72349e9f8acc5;p=dpdk.git diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 4163c928c7..2d2b11a198 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -51,6 +51,7 @@ #include #include #include +#include #include "rte_fbk_hash.h" @@ -79,10 +80,12 @@ rte_fbk_hash_find_existing(const char *name) return NULL; } + rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); TAILQ_FOREACH(h, fbk_hash_list, next) { if (strncmp(name, h->name, RTE_FBK_HASH_NAMESIZE) == 0) break; } + rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK); if (h == NULL) rte_errno = ENOENT; return h; @@ -129,19 +132,22 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) rte_snprintf(hash_name, sizeof(hash_name), "FBK_%s", params->name); + rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); + /* guarantee there's no existing */ TAILQ_FOREACH(ht, fbk_hash_list, next) { if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0) break; } if (ht != NULL) - return NULL; + goto exit; /* Allocate memory for table. */ ht = (struct rte_fbk_hash_table *)rte_malloc_socket(hash_name, mem_size, 0, params->socket_id); if (ht == NULL) - return NULL; + goto exit; + memset(ht, 0, mem_size); /* Set up hash table context. */ @@ -165,6 +171,10 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) } TAILQ_INSERT_TAIL(fbk_hash_list, ht, next); + +exit: + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + return ht; }