From b68234b57d435f08d5d783b857f7626128499587 Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Sat, 4 Oct 2014 11:42:28 +0000 Subject: replace mutexes to serialise the operations on the flag that restricts the number of contexts that are refilling the rx rings with atomic ops. this is borrowed from code i wrote for the scsi midlayer but cant put in yet because i havent got atomic.h up to scrach on all archs yet. the archs myx runs on do have enough atomic.h to be fine though. --- sys/dev/pci/if_myx.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/sys/dev/pci/if_myx.c b/sys/dev/pci/if_myx.c index 69cad8f6f52..0e601f76c4b 100644 --- a/sys/dev/pci/if_myx.c +++ b/sys/dev/pci/if_myx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_myx.c,v 1.69 2014/10/03 13:41:55 dlg Exp $ */ +/* $OpenBSD: if_myx.c,v 1.70 2014/10/04 11:42:27 dlg Exp $ */ /* * Copyright (c) 2007 Reyk Floeter @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -2049,27 +2050,16 @@ myx_ring_lock_init(struct myx_ring_lock *mrl) int myx_ring_enter(struct myx_ring_lock *mrl) { - int rv = 1; - - mtx_enter(&mrl->mrl_mtx); - if (++mrl->mrl_running > 1) - rv = 0; - mtx_leave(&mrl->mrl_mtx); - - return (rv); + return (atomic_inc_int_nv(&mrl->mrl_running) == 1); } int myx_ring_leave(struct myx_ring_lock *mrl) { - int rv = 1; + if (atomic_cas_uint(&mrl->mrl_running, 1, 0) == 1) + return (1); - mtx_enter(&mrl->mrl_mtx); - if (--mrl->mrl_running > 0) { - mrl->mrl_running = 1; - rv = 0; - } - mtx_leave(&mrl->mrl_mtx); + mrl->mrl_running = 1; - return (rv); + return (0); } -- cgit v1.2.3