summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorThordur I. Bjornsson <thib@cvs.openbsd.org>2007-07-02 17:11:30 +0000
committerThordur I. Bjornsson <thib@cvs.openbsd.org>2007-07-02 17:11:30 +0000
commit6585e412a838c23d2d2ea943eaf3c59ce5fbae3c (patch)
tree01ae42472c146d1b366f59660535282afa3562f8 /sys
parent9baea3e4cad8ada43fa6ccb8936d89ebee824b3a (diff)
replace two lockmgr lock with rwlocks.
been in snaps for a week, no objection from deraadt@ for putting this in. ok tom@ (for gdt)
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/i386/i386/apm.c35
-rw-r--r--sys/arch/i386/i386/gdt.c35
2 files changed, 30 insertions, 40 deletions
diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c
index 48c92d866b6..58016d4da49 100644
--- a/sys/arch/i386/i386/apm.c
+++ b/sys/arch/i386/i386/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.75 2007/05/29 08:22:14 gwk Exp $ */
+/* $OpenBSD: apm.c,v 1.76 2007/07/02 17:11:29 thib Exp $ */
/*-
* Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
@@ -45,7 +45,7 @@
#include <sys/signalvar.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
-#include <sys/lock.h>
+#include <sys/rwlock.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/malloc.h>
@@ -75,9 +75,6 @@
#define DPRINTF(x) /**/
#endif
-#define APM_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL)
-#define APM_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL)
-
struct cfdriver apm_cd = {
NULL, "apm", DV_DULL
};
@@ -88,7 +85,7 @@ struct apm_softc {
int sc_flags;
int batt_life;
struct proc *sc_thread;
- struct lock sc_lock;
+ struct rwlock sc_lock;
};
#define SCFLAG_OREAD 0x0000001
#define SCFLAG_OWRITE 0x0000002
@@ -891,7 +888,7 @@ apmattach(struct device *parent, struct device *self, void *aux)
apm_perror("get power status", &regs);
apm_cpu_busy();
- lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0);
+ rw_init(&sc->sc_lock, "apmlk");
/*
* Do a check once, ignoring any errors. This avoids
@@ -946,9 +943,9 @@ apm_thread(void *v)
struct apm_softc *sc = v;
for (;;) {
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
(void) apm_periodic_check(sc);
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
tsleep(&lbolt, PWAIT, "apmev", 0);
}
}
@@ -970,7 +967,7 @@ apmopen(dev_t dev, int flag, int mode, struct proc *p)
DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n",
APMDEV(dev), p->p_pid, flag, mode));
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
switch (APMDEV(dev)) {
case APMDEV_CTL:
if (!(flag & FWRITE)) {
@@ -994,7 +991,7 @@ apmopen(dev_t dev, int flag, int mode, struct proc *p)
error = ENXIO;
break;
}
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
return error;
}
@@ -1010,7 +1007,7 @@ apmclose(dev_t dev, int flag, int mode, struct proc *p)
DPRINTF(("apmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode));
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
switch (APMDEV(dev)) {
case APMDEV_CTL:
sc->sc_flags &= ~SCFLAG_OWRITE;
@@ -1019,7 +1016,7 @@ apmclose(dev_t dev, int flag, int mode, struct proc *p)
sc->sc_flags &= ~SCFLAG_OREAD;
break;
}
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
return 0;
}
@@ -1035,7 +1032,7 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
!(sc = apm_cd.cd_devs[APMUNIT(dev)]))
return ENXIO;
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
switch (cmd) {
/* some ioctl names from linux */
case APM_IOC_STANDBY:
@@ -1133,7 +1130,7 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
error = ENOTTY;
}
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
return error;
}
@@ -1142,9 +1139,9 @@ filt_apmrdetach(struct knote *kn)
{
struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
}
int
@@ -1176,8 +1173,8 @@ apmkqfilter(dev_t dev, struct knote *kn)
kn->kn_hook = (caddr_t)sc;
- APM_LOCK(sc);
+ rw_enter_write(&sc->sc_lock);
SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
- APM_UNLOCK(sc);
+ rw_exit_write(&sc->sc_lock);
return (0);
}
diff --git a/sys/arch/i386/i386/gdt.c b/sys/arch/i386/i386/gdt.c
index 44c48835d1f..8bfe8299804 100644
--- a/sys/arch/i386/i386/gdt.c
+++ b/sys/arch/i386/i386/gdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gdt.c,v 1.26 2007/05/17 15:00:02 art Exp $ */
+/* $OpenBSD: gdt.c,v 1.27 2007/07/02 17:11:29 thib Exp $ */
/* $NetBSD: gdt.c,v 1.28 2002/12/14 09:38:50 junyoung Exp $ */
/*-
@@ -65,6 +65,7 @@
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/user.h>
+#include <sys/rwlock.h>
#include <uvm/uvm.h>
@@ -77,11 +78,8 @@ int gdt_size; /* total number of GDT entries */
int gdt_next; /* next available slot for sweeping */
int gdt_free; /* next free slot; terminated with GNULL_SEL */
-struct simplelock gdt_simplelock;
-struct lock gdt_lock_store;
+struct rwlock gdt_lock_store = RWLOCK_INITIALIZER("gdtlk");
-static __inline void gdt_lock(void);
-static __inline void gdt_unlock(void);
void gdt_grow(void);
int gdt_get_slot(void);
void gdt_put_slot(int);
@@ -90,19 +88,17 @@ void gdt_put_slot(int);
* Lock and unlock the GDT, to avoid races in case gdt_{ge,pu}t_slot() sleep
* waiting for memory.
*/
-static __inline void
-gdt_lock()
-{
- if (curproc != NULL)
- lockmgr(&gdt_lock_store, LK_EXCLUSIVE, &gdt_simplelock);
-}
-
-static __inline void
-gdt_unlock()
-{
- if (curproc != NULL)
- lockmgr(&gdt_lock_store, LK_RELEASE, &gdt_simplelock);
-}
+#define gdt_lock() \
+ do { \
+ if (curproc != NULL) \
+ rw_enter_write(&gdt_lock_store);\
+ } while (0)
+
+#define gdt_unlock() \
+ do { \
+ if (curproc != NULL) \
+ rw_exit_write(&gdt_lock_store); \
+ } while (0)
/* XXX needs spinlocking if we ever mean to go finegrained. */
void
@@ -132,9 +128,6 @@ gdt_init()
vaddr_t va;
struct cpu_info *ci = &cpu_info_primary;
- simple_lock_init(&gdt_simplelock);
- lockinit(&gdt_lock_store, PZERO, "gdtlck", 0, 0);
-
max_len = MAXGDTSIZ * sizeof(union descriptor);
min_len = MINGDTSIZ * sizeof(union descriptor);