udp: allocate rx lock only for non-connected

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ib5395a51fbfb2123549f7c96534fa763b4669243
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index 00d9ec1..1878d2e 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -116,7 +116,6 @@
   uc->c_c_index = uc - um->connections[thread_index];
   uc->c_thread_index = thread_index;
   uc->c_proto = TRANSPORT_PROTO_UDP;
-  clib_spinlock_init (&uc->rx_lock);
   return uc;
 }
 
@@ -390,9 +389,14 @@
   uc->mss = rmt->mss ? rmt->mss : udp_default_mtu (um, uc->c_is_ip4);
   uc->flags |= UDP_CONN_F_OWNS_PORT;
   if (rmt->transport_flags & TRANSPORT_CFG_F_CONNECTED)
-    uc->flags |= UDP_CONN_F_CONNECTED;
+    {
+      uc->flags |= UDP_CONN_F_CONNECTED;
+    }
   else
-    uc->c_flags |= TRANSPORT_CONNECTION_F_CLESS;
+    {
+      clib_spinlock_init (&uc->rx_lock);
+      uc->c_flags |= TRANSPORT_CONNECTION_F_CLESS;
+    }
 
   return uc->c_c_index;
 }