summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2014-10-04 11:42:28 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2014-10-04 11:42:28 +0000
commitb68234b57d435f08d5d783b857f7626128499587 (patch)
tree1ba597cb559cd412ce2aa64c19e20646c84a1c5c /sys/dev/pci
parent1b5ea667c93ee4172b58318273a773f71253f862 (diff)
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.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/if_myx.c24
1 files 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 <reyk@openbsd.org>
@@ -33,6 +33,7 @@
#include <sys/timeout.h>
#include <sys/device.h>
#include <sys/queue.h>
+#include <sys/atomic.h>
#include <machine/bus.h>
#include <machine/intr.h>
@@ -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);
}