vppinfra: add spinlock inline functions

Change-Id: I86089e9bb604adfc260a111685001be1c897ce53
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index 5fdc59f..2028510 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -229,11 +229,7 @@
   apif->next_rx_frame = 0;
 
   if (tm->n_vlib_mains > 1)
-    {
-      apif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
-					    CLIB_CACHE_LINE_BYTES);
-      memset ((void *) apif->lockp, 0, CLIB_CACHE_LINE_BYTES);
-    }
+    clib_spinlock_init (&apif->lockp);
 
   {
     unix_file_t template = { 0 };
diff --git a/src/vnet/devices/af_packet/af_packet.h b/src/vnet/devices/af_packet/af_packet.h
index 50ec237..77a2c7a 100644
--- a/src/vnet/devices/af_packet/af_packet.h
+++ b/src/vnet/devices/af_packet/af_packet.h
@@ -17,10 +17,12 @@
  *------------------------------------------------------------------
  */
 
+#include <vppinfra/lock.h>
+
 typedef struct
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
-  volatile u32 *lockp;
+  clib_spinlock_t lockp;
   u8 *host_if_name;
   int fd;
   struct tpacket_req *rx_req;
diff --git a/src/vnet/devices/af_packet/device.c b/src/vnet/devices/af_packet/device.c
index 9a94fc5..2ba3f57 100644
--- a/src/vnet/devices/af_packet/device.c
+++ b/src/vnet/devices/af_packet/device.c
@@ -92,11 +92,7 @@
   struct tpacket2_hdr *tph;
   u32 frame_not_ready = 0;
 
-  if (PREDICT_FALSE (apif->lockp != 0))
-    {
-      while (__sync_lock_test_and_set (apif->lockp, 1))
-	;
-    }
+  clib_spinlock_lock_if_init (&apif->lockp);
 
   while (n_left > 0)
     {
@@ -159,8 +155,7 @@
 	}
     }
 
-  if (PREDICT_FALSE (apif->lockp != 0))
-    *apif->lockp = 0;
+  clib_spinlock_unlock_if_init (&apif->lockp);
 
   if (PREDICT_FALSE (frame_not_ready))
     vlib_error_count (vm, node->node_index,