-/* $OpenBSD: mem.c,v 1.16 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.17 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.11 2003/10/16 12:02:58 jdolecek Exp $ */
/*
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/fcntl.h>
+#include <sys/rwlock.h>
#include <machine/cpu.h>
#include <arm/conf.h>
extern char *memhook; /* poor name! */
caddr_t zeropage;
-int physlock;
/* open counter for aperture */
#ifdef APERTURE
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
vaddr_t o, v;
size_t c;
struct iovec *iov;
if (minor(dev) == DEV_MEM) {
/* lock against other uses of shared vmmap */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
+
}
while (uio->uio_resid > 0 && error == 0) {
iov = uio->uio_iov;
}
}
if (minor(dev) == DEV_MEM) {
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}
-/* $OpenBSD: mem.c,v 1.27 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.28 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.13 1996/03/30 21:12:16 christos Exp $ */
/*
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
+#include <sys/rwlock.h>
#include <sys/conf.h>
#include <sparc/sparc/vaddrs.h>
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
off_t o;
paddr_t pa;
vaddr_t va;
size_t c;
struct iovec *iov;
int error = 0;
- static int physlock;
if (minor(dev) == 0) {
/* lock against other uses of shared mem_page */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
if (mem_page == 0)
mem_page = uvm_km_valloc_wait(kernel_map, NBPG);
if (mem_page == 0)
}
if (minor(dev) == 0) {
unlock:
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}
-/* $OpenBSD: mem.c,v 1.16 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.17 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.18 2001/04/24 04:31:12 thorpej Exp $ */
/*
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
+#include <sys/rwlock.h>
#include <sys/conf.h>
#include <machine/conf.h>
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
vaddr_t o, v;
size_t c;
struct iovec *iov;
int error = 0;
- static int physlock;
vm_prot_t prot;
extern caddr_t vmmap;
if (minor(dev) == 0) {
/* lock against other uses of shared vmmap */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
}
while (uio->uio_resid > 0 && error == 0) {
int n;
}
if (minor(dev) == 0) {
unlock:
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}