summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-03-27 17:08:20 +0200
committerDave Barach <openvpp@barachs.net>2017-03-30 14:14:26 +0000
commit1927da29ccbe1d4cc8e59ccfa197eb41c257814f (patch)
tree226487b33921b9a45f78016d078548a6815c3431 /src/plugins
parentb18e0de1f9630fab8b3d6ffe85c7a6ee35a6fdac (diff)
vppinfra: add spinlock inline functions
Change-Id: I86089e9bb604adfc260a111685001be1c897ce53 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/memif/device.c21
-rw-r--r--src/plugins/memif/memif.c12
-rw-r--r--src/plugins/memif/memif.h4
3 files changed, 7 insertions, 30 deletions
diff --git a/src/plugins/memif/device.c b/src/plugins/memif/device.c
index 446537a3792..4faeb0554f3 100644
--- a/src/plugins/memif/device.c
+++ b/src/plugins/memif/device.c
@@ -79,23 +79,6 @@ format_memif_tx_trace (u8 * s, va_list * args)
}
static_always_inline void
-memif_interface_lock (memif_if_t * mif)
-{
- if (PREDICT_FALSE (mif->lockp != 0))
- {
- while (__sync_lock_test_and_set (mif->lockp, 1))
- ;
- }
-}
-
-static_always_inline void
-memif_interface_unlock (memif_if_t * mif)
-{
- if (PREDICT_FALSE (mif->lockp != 0))
- *mif->lockp = 0;
-}
-
-static_always_inline void
memif_prefetch_buffer_and_data (vlib_main_t * vm, u32 bi)
{
vlib_buffer_t *b = vlib_get_buffer (vm, bi);
@@ -117,7 +100,7 @@ memif_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
u16 head, tail;
u16 free_slots;
- memif_interface_lock (mif);
+ clib_spinlock_lock_if_init (&mif->lockp);
/* free consumed buffers */
@@ -210,7 +193,7 @@ memif_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
CLIB_MEMORY_STORE_BARRIER ();
ring->head = head;
- memif_interface_unlock (mif);
+ clib_spinlock_unlock (&mif->lockp);
if (n_left)
{
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 7ba67c5b898..cf8ca577d54 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -716,11 +716,7 @@ memif_close_if (memif_main_t * mm, memif_if_t * mif)
}
}
- if (mif->lockp != 0)
- {
- clib_mem_free ((void *) mif->lockp);
- mif->lockp = 0;
- }
+ clib_spinlock_free (&mif->lockp);
mhash_unset (&mm->if_index_by_key, &mif->key, &mif->if_index);
vec_free (mif->socket_filename);
@@ -783,11 +779,7 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
mif->connection.fd = mif->interrupt_line.fd = -1;
if (tm->n_vlib_mains > 1)
- {
- mif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- memset ((void *) mif->lockp, 0, CLIB_CACHE_LINE_BYTES);
- }
+ clib_spinlock_init (&mif->lockp);
if (!args->hw_addr_set)
{
diff --git a/src/plugins/memif/memif.h b/src/plugins/memif/memif.h
index a7a88e07b0e..f57170f8e6f 100644
--- a/src/plugins/memif/memif.h
+++ b/src/plugins/memif/memif.h
@@ -15,6 +15,8 @@
*------------------------------------------------------------------
*/
+#include <vppinfra/lock.h>
+
typedef struct
{
u16 version;
@@ -98,7 +100,7 @@ typedef struct
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- volatile u32 *lockp;
+ clib_spinlock_t lockp;
u32 flags;
#define MEMIF_IF_FLAG_ADMIN_UP (1 << 0)
#define MEMIF_IF_FLAG_IS_SLAVE (1 << 1)