Subject: Re: multiple copies of arp_lock_try()
To: None <tech-net@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-net
Date: 06/24/2002 12:38:44
>	we have multiple copies of arp_lock_try() in netinet/if_arp.c and
>	netinet/if_ieee1394arp.c.  does it make sense to merge them?
>	(i understand __inline will become meaningless)

	retry.

itojun


Index: if_arp.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/if_arp.c,v
retrieving revision 1.81
diff -u -r1.81 if_arp.c
--- if_arp.c	2002/06/09 16:33:37	1.81
+++ if_arp.c	2002/06/24 03:39:52
@@ -110,7 +110,6 @@
 #include <net/if_types.h>
 #include <net/route.h>
 
-
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/in_var.h>
@@ -249,11 +248,8 @@
  */
 
 int	arp_locked;
-
-static __inline int arp_lock_try __P((int));
-static __inline void arp_unlock __P((void));
 
-static __inline int
+int
 arp_lock_try(int recurse)
 {
 	int s;
@@ -272,7 +268,7 @@
 	return (1);
 }
 
-static __inline void
+void
 arp_unlock()
 {
 	int s;
@@ -1411,3 +1407,4 @@
 #endif
 #endif /* INET */
 
+#endif /* _NETINET_IF_ARP_H_ */
Index: if_ieee1394arp.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/if_ieee1394arp.c,v
retrieving revision 1.8
diff -u -r1.8 if_ieee1394arp.c
--- if_ieee1394arp.c	2002/06/09 16:33:37	1.8
+++ if_ieee1394arp.c	2002/06/24 03:39:52
@@ -113,42 +113,6 @@
 } arpstat;
 #endif
 
-static __inline int arp_lock_try(int);
-static __inline void arp_unlock(void);
-
-static __inline int
-arp_lock_try(recurse)
-	int recurse;
-{
-	int s;
-
-	/*
-	 * Use splvm() -- we're blocking things that would cause
-	 * mbuf allocation.
-	 */
-	s = splvm();
-	if (!recurse && arp_locked) {
-		splx(s);
-		return 0;
-	}
-	arp_locked++;
-	splx(s);
-	return 1;
-}
-
-static __inline void
-arp_unlock()
-{
-	int s;
-
-	s = splvm();
-	arp_locked--;
-	splx(s);
-}
-
-#define	ARP_LOCK(x)	(void)arp_lock_try(x)
-#define	ARP_UNLOCK()	arp_unlock();
-
 /*
  * Parallel to llc_rtrequest.
  */
Index: if_inarp.h
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/if_inarp.h,v
retrieving revision 1.32
diff -u -r1.32 if_inarp.h
--- if_inarp.h	2001/01/17 04:05:44	1.32
+++ if_inarp.h	2002/06/24 03:39:52
@@ -79,6 +79,33 @@
 void in_revarpinput __P((struct mbuf *));
 void revarprequest __P((struct ifnet *));
 int revarpwhoarewe __P((struct ifnet *, struct in_addr *, struct in_addr *));
+
+/* arp lock */
+extern int arp_locked;
+extern int arp_lock_try __P((int));
+extern void arp_unlock __P((void));
+
+#ifdef DIAGNOSTIC
+#define	ARP_LOCK(recurse)						\
+do {									\
+	if (arp_lock_try(recurse) == 0) {				\
+		printf("%s:%d: arp already locked\n", __FILE__, __LINE__); \
+		panic("arp_lock");					\
+	}								\
+} while (0)
+#define	ARP_LOCK_CHECK()						\
+do {									\
+	if (arp_locked == 0) {						\
+		printf("%s:%d: arp lock not held\n", __FILE__, __LINE__); \
+		panic("arp lock check");				\
+	}								\
+} while (0)
+#else
+#define	ARP_LOCK(x)		(void) arp_lock_try(x)
+#define	ARP_LOCK_CHECK()	/* nothing */
+#endif
+
+#define	ARP_UNLOCK()		arp_unlock()
 #endif
 
 #endif /* _NETINET_IF_INARP_H_ */