summaryrefslogtreecommitdiff
path: root/lib/librte_lpm
diff options
context:
space:
mode:
authorIntel <intel.com>2012-12-20 00:00:00 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2013-07-25 15:23:27 +0200
commit916e4f4f4e45a1d3cdd473cf9ef71c7212b83d40 (patch)
tree9d84c264f445baea2e7d8c10cf6cd0c5ed0845d5 /lib/librte_lpm
parentb6a468ad41d59205ae5b60cf5c8212e130c3e5d7 (diff)
downloaddpdk-916e4f4f4e45a1d3cdd473cf9ef71c7212b83d40.zip
dpdk-916e4f4f4e45a1d3cdd473cf9ef71c7212b83d40.tar.gz
dpdk-916e4f4f4e45a1d3cdd473cf9ef71c7212b83d40.tar.xz
memory: fix for multi process support
Signed-off-by: Intel
Diffstat (limited to 'lib/librte_lpm')
-rw-r--r--lib/librte_lpm/rte_lpm.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index b1bc6b3..10705fc 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -52,6 +52,8 @@
#include <rte_per_lcore.h>
#include <rte_string_fns.h>
#include <rte_errno.h>
+#include <rte_rwlock.h>
+#include <rte_spinlock.h>
#include "rte_lpm.h"
@@ -126,10 +128,12 @@ rte_lpm_find_existing(const char *name)
return NULL;
}
+ rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
TAILQ_FOREACH(l, lpm_list, next) {
if (strncmp(name, l->name, RTE_LPM_NAMESIZE) == 0)
break;
}
+ rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
if (l == NULL)
rte_errno = ENOENT;
@@ -179,20 +183,22 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
/* Determine the amount of memory to allocate. */
mem_size = sizeof(*lpm) + (sizeof(lpm->rules_tbl[0]) * max_rules);
+ rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+
/* guarantee there's no existing */
TAILQ_FOREACH(lpm, lpm_list, next) {
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
if (lpm != NULL)
- return NULL;
+ goto exit;
/* Allocate memory to store the LPM data structures. */
lpm = (struct rte_lpm *)rte_zmalloc_socket(mem_name, mem_size,
CACHE_LINE_SIZE, socket_id);
if (lpm == NULL) {
RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
- return NULL;
+ goto exit;
}
/* Save user arguments. */
@@ -201,6 +207,9 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
TAILQ_INSERT_TAIL(lpm_list, lpm, next);
+exit:
+ rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+
return lpm;
}