Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lmc(4) mutex locking



To remove gcc extensions from the lmc(4) driver, I converted the driver to 
mutexes.  Does it look correct?  Can anybody test it?
 -- Gregory McGarry <g.mcgarry%ieee.org@localhost>



      Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/mail
Index: if_lmc.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_lmc.c,v
retrieving revision 1.42
diff -u -r1.42 if_lmc.c
--- if_lmc.c    12 Jun 2008 22:44:47 -0000      1.42
+++ if_lmc.c    26 Jun 2008 02:04:08 -0000
@@ -7167,7 +7167,7 @@
     }
 
   /* Initialize the top-half and bottom-half locks. */
-  __cpu_simple_lock_init(&sc->top_lock);
+  mutex_init(&sc->top_lock, MUTEX_DEFAULT, IPL_NET);
   __cpu_simple_lock_init(&sc->bottom_lock);
 
   /* Initialize the driver. */
@@ -7191,6 +7191,9 @@
   if (sc->csr_handle)
     bus_space_unmap(sc->csr_tag, sc->csr_handle, TLP_CSR_SIZE);
 
+  /* Destroy locks. */
+  mutex_destroy(&sc->top_lock);
+
   return 0;
   }
 
Index: if_lmc.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_lmc.h,v
retrieving revision 1.12
diff -u -r1.12 if_lmc.h
--- if_lmc.h    12 Jun 2008 22:44:47 -0000      1.12
+++ if_lmc.h    26 Jun 2008 02:04:09 -0000
@@ -1055,10 +1055,9 @@
 # define WRITE_CSR(sc, csr, val) bus_space_write_4((sc)->csr_tag, 
(sc)->csr_handle, csr, val)
 # define NAME_UNIT             device_xname(&sc->dev)
 # define BOOT_VERBOSE          (boothowto & AB_VERBOSE)
-# define TOP_LOCK(sc)          ({ while 
(__cpu_simple_lock_try(&(sc)->top_lock)==0) \
-                                tsleep((sc), PCATCH|PZERO, DEVICE_NAME, 1); 0; 
})
-# define TOP_TRYLOCK(sc)       __cpu_simple_lock_try(&(sc)->top_lock)
-# define TOP_UNLOCK(sc)                __cpu_simple_unlock  (&(sc)->top_lock)
+# define TOP_LOCK(sc)          (mutex_enter(&(sc)->top_lock), 0)
+# define TOP_TRYLOCK(sc)       mutex_tryenter(&(sc)->top_lock)
+# define TOP_UNLOCK(sc)                mutex_exit(&(sc)->top_lock)
 # define BOTTOM_TRYLOCK(sc)    __cpu_simple_lock_try(&(sc)->bottom_lock)
 # define BOTTOM_UNLOCK(sc)     __cpu_simple_unlock  (&(sc)->bottom_lock)
 # define CHECK_CAP             kauth_authorize_generic(curlwp->l_cred, 
KAUTH_GENERIC_ISSUSER, NULL)
@@ -1290,7 +1289,11 @@
   void *irq_cookie;
   void *sdh_cookie;
   struct mbuf *tx_mbuf;                        /* hang mbuf here while 
building dma descs */
+#if defined(__NetBSD__)
+  kmutex_t top_lock;                   /* lock card->watchdog vs ioctls        
   */
+#else
   __cpu_simple_lock_t top_lock;                /* lock card->watchdog vs 
ioctls           */
+#endif
   __cpu_simple_lock_t bottom_lock;     /* lock buf queues & descriptor rings   
*/
 #endif                                 /* __NetBSD__ || __OpenBSD__ */
 


Home | Main Index | Thread Index | Old Index