update copyright date to 2013
[dpdk.git] / lib / librte_hash / rte_fbk_hash.c
index fa397f5..1be2d0a 100644 (file)
@@ -1,7 +1,7 @@
 /**
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
  *   Redistribution and use in source and binary forms, with or without 
@@ -51,6 +51,7 @@
 #include <rte_string_fns.h>
 #include <rte_cpuflags.h>
 #include <rte_log.h>
+#include <rte_spinlock.h>
 
 #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;
@@ -122,25 +125,29 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
                        (params->entries_per_bucket == 0) ||
                        (params->entries_per_bucket > params->entries) ||
                        (params->entries > RTE_FBK_HASH_ENTRIES_MAX) ||
-                       (params->entries_per_bucket > RTE_FBK_HASH_ENTRIES_MAX)){
+                       (params->entries_per_bucket > RTE_FBK_HASH_ENTRIES_PER_BUCKET_MAX)){
                rte_errno = EINVAL;
                return NULL;
        }
 
        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(hash_name, mem_size, 0);
+       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. */
@@ -164,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;
 }