summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/man9/lock.917
-rw-r--r--sys/kern/kern_lock.c74
-rw-r--r--sys/sys/lock.h20
3 files changed, 15 insertions, 96 deletions
diff --git a/share/man/man9/lock.9 b/share/man/man9/lock.9
index 13c91943fd5..cfdc2f12ad0 100644
--- a/share/man/man9/lock.9
+++ b/share/man/man9/lock.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: lock.9,v 1.13 2007/02/03 16:58:30 pedro Exp $
+.\" $OpenBSD: lock.9,v 1.14 2007/04/11 12:06:34 miod Exp $
.\" $NetBSD: lock.9,v 1.12 2001/11/01 01:13:43 wiz Exp $
.\"
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -200,18 +200,6 @@ process holding an exclusive-access lock may get additional
exclusive-access locks if it explicitly sets the LK_CANRECURSE flag in
the lock request, or if the LK_CANRECURSE flag was set when the lock
was initialised.
-.It LK_UPGRADE
-The process must hold a shared-access lock that it wants to have
-upgraded to an exclusive-access lock.
-Other processes may get exclusive
-access to the protected resource between the time that the upgrade is
-requested and the time that it is granted.
-.It LK_DOWNGRADE
-The process must hold an exclusive-access lock that it wants to have
-downgraded to a shared-access lock.
-If the process holds multiple
-(recursive) exclusive-access locks, they will all be downgraded to
-shared-access locks.
.It LK_RELEASE
Release one instance of a lock.
.It LK_DRAIN
@@ -289,9 +277,12 @@ in
.Sh SEE ALSO
.Xr mutex 9 ,
.Xr pmap 9 ,
+.Xr rwlock 9 ,
.Xr spl 9 ,
.Xr tsleep 9 ,
.Xr uvm 9
.Sh HISTORY
The kernel locking API first appeared in
.Bx 4.4 -lite2 .
+It was progressively deprecated in favor of
+.Xr rwlock 9 .
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index d0b418a7b1f..6d51847a770 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lock.c,v 1.25 2007/03/15 10:22:30 art Exp $ */
+/* $OpenBSD: kern_lock.c,v 1.26 2007/04/11 12:06:37 miod Exp $ */
/*
* Copyright (c) 1995
@@ -287,7 +287,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
* If just polling, check to see if we will block.
*/
if ((extflags & LK_NOWAIT) && (lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE))) {
+ (LK_HAVE_EXCL | LK_WANT_EXCL))) {
error = EBUSY;
break;
}
@@ -295,7 +295,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
* Wait for exclusive locks and upgrades to clear.
*/
ACQUIRE(lkp, error, extflags, 0, lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE));
+ (LK_HAVE_EXCL | LK_WANT_EXCL));
if (error)
break;
lkp->lk_sharecount++;
@@ -308,9 +308,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
*/
lkp->lk_sharecount++;
COUNT(lkp, p, cpu_id, 1);
- /* FALLTHROUGH */
- case LK_DOWNGRADE:
if (WEHOLDIT(lkp, pid, cpu_id) == 0 ||
lkp->lk_exclusivecount == 0)
panic("lockmgr: not holding exclusive lock");
@@ -326,61 +324,6 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
WAKEUP_WAITER(lkp);
break;
- case LK_UPGRADE:
- /*
- * Upgrade a shared lock to an exclusive one. If another
- * shared lock has already requested an upgrade to an
- * exclusive lock, our shared lock is released and an
- * exclusive lock is requested (which will be granted
- * after the upgrade). If we return an error, the file
- * will always be unlocked.
- */
- if (WEHOLDIT(lkp, pid, cpu_id) || lkp->lk_sharecount <= 0)
- panic("lockmgr: upgrade exclusive lock");
- lkp->lk_sharecount--;
- COUNT(lkp, p, cpu_id, -1);
- /*
- * If we are just polling, check to see if we will block.
- */
- if ((extflags & LK_NOWAIT) &&
- ((lkp->lk_flags & LK_WANT_UPGRADE) ||
- lkp->lk_sharecount > 1)) {
- error = EBUSY;
- break;
- }
- if ((lkp->lk_flags & LK_WANT_UPGRADE) == 0) {
- /*
- * We are first shared lock to request an upgrade, so
- * request upgrade and wait for the shared count to
- * drop to zero, then take exclusive lock.
- */
- lkp->lk_flags |= LK_WANT_UPGRADE;
- ACQUIRE(lkp, error, extflags, 0, lkp->lk_sharecount);
- lkp->lk_flags &= ~LK_WANT_UPGRADE;
- if (error)
- break;
- lkp->lk_flags |= LK_HAVE_EXCL;
- SETHOLDER(lkp, pid, cpu_id);
-#if defined(LOCKDEBUG)
- lkp->lk_lock_file = file;
- lkp->lk_lock_line = line;
-#endif
- HAVEIT(lkp);
- if (lkp->lk_exclusivecount != 0)
- panic("lockmgr: non-zero exclusive count");
- lkp->lk_exclusivecount = 1;
- COUNT(lkp, p, cpu_id, 1);
- break;
- }
- /*
- * Someone else has requested upgrade. Release our shared
- * lock, awaken upgrade requestor if we are the last shared
- * lock, then request an exclusive lock.
- */
- if (lkp->lk_sharecount == 0)
- WAKEUP_WAITER(lkp);
- /* FALLTHROUGH */
-
case LK_EXCLUSIVE:
if (WEHOLDIT(lkp, pid, cpu_id)) {
/*
@@ -401,7 +344,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
* If we are just polling, check to see if we will sleep.
*/
if ((extflags & LK_NOWAIT) && ((lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE)) ||
+ (LK_HAVE_EXCL | LK_WANT_EXCL)) ||
lkp->lk_sharecount != 0)) {
error = EBUSY;
break;
@@ -417,8 +360,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
/*
* Wait for shared locks and upgrades to finish.
*/
- ACQUIRE(lkp, error, extflags, 0, lkp->lk_sharecount != 0 ||
- (lkp->lk_flags & LK_WANT_UPGRADE));
+ ACQUIRE(lkp, error, extflags, 0, lkp->lk_sharecount != 0);
lkp->lk_flags &= ~LK_WANT_EXCL;
if (error)
break;
@@ -477,14 +419,14 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
* If we are just polling, check to see if we will sleep.
*/
if ((extflags & LK_NOWAIT) && ((lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE)) ||
+ (LK_HAVE_EXCL | LK_WANT_EXCL)) ||
lkp->lk_sharecount != 0 || lkp->lk_waitcount != 0)) {
error = EBUSY;
break;
}
ACQUIRE(lkp, error, extflags, 1,
((lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE)) ||
+ (LK_HAVE_EXCL | LK_WANT_EXCL)) ||
lkp->lk_sharecount != 0 ||
lkp->lk_waitcount != 0));
if (error)
@@ -508,7 +450,7 @@ lockmgr(__volatile struct lock *lkp, u_int flags, struct simplelock *interlkp)
}
if ((lkp->lk_flags & LK_WAITDRAIN) != 0 &&
((lkp->lk_flags &
- (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE)) == 0 &&
+ (LK_HAVE_EXCL | LK_WANT_EXCL)) == 0 &&
lkp->lk_sharecount == 0 && lkp->lk_waitcount == 0)) {
lkp->lk_flags &= ~LK_WAITDRAIN;
wakeup((void *)&lkp->lk_flags);
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 5a5d4e69015..cf658fd9307 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.h,v 1.16 2007/02/03 16:48:23 miod Exp $ */
+/* $OpenBSD: lock.h,v 1.17 2007/04/11 12:06:37 miod Exp $ */
/*
* Copyright (c) 1995
@@ -92,14 +92,6 @@ struct lock {
* locks if it explicitly sets the LK_CANRECURSE flag in the lock
* request, or if the LK_CANRECUSE flag was set when the lock was
* initialized.
- * LK_UPGRADE - the process must hold a shared lock that it wants to
- * have upgraded to an exclusive lock. Other processes may get
- * exclusive access to the resource between the time that the upgrade
- * is requested and the time that it is granted.
- * LK_DOWNGRADE - the process must hold an exclusive lock that it wants
- * to have downgraded to a shared lock. If the process holds multiple
- * (recursive) exclusive locks, they will all be downgraded to shared
- * locks.
* LK_RELEASE - release one instance of a lock.
* LK_DRAIN - wait for all activity on the lock to end, then mark it
* decommissioned. This feature is used before freeing a lock that
@@ -110,8 +102,6 @@ struct lock {
#define LK_TYPE_MASK 0x0000000f /* type of lock sought */
#define LK_SHARED 0x00000001 /* shared lock */
#define LK_EXCLUSIVE 0x00000002 /* exclusive lock */
-#define LK_UPGRADE 0x00000003 /* shared-to-exclusive upgrade */
-#define LK_DOWNGRADE 0x00000005 /* exclusive-to-shared downgrade */
#define LK_RELEASE 0x00000006 /* release any type of lock */
#define LK_DRAIN 0x00000007 /* wait for all lock activity to end */
/*
@@ -120,7 +110,7 @@ struct lock {
* The first three flags may be set in lock_init to set their mode permanently,
* or passed in as arguments to the lock manager.
*/
-#define LK_EXTFLG_MASK 0x00700070 /* mask of external flags */
+#define LK_EXTFLG_MASK 0x00200070 /* mask of external flags */
#define LK_NOWAIT 0x00000010 /* do not sleep to await lock */
#define LK_SLEEPFAIL 0x00000020 /* sleep, then return failure */
#define LK_CANRECURSE 0x00000040 /* allow recursive exclusive lock */
@@ -130,7 +120,6 @@ struct lock {
*
* These flags are used internally to the lock manager.
*/
-#define LK_WANT_UPGRADE 0x00001000 /* waiting for share-to-excl upgrade */
#define LK_WANT_EXCL 0x00002000 /* exclusive lock sought */
#define LK_HAVE_EXCL 0x00004000 /* exclusive lock obtained */
#define LK_WAITDRAIN 0x00008000 /* process waiting for lock to drain */
@@ -150,16 +139,13 @@ struct lock {
*
* Successfully obtained locks return 0. Locks will always succeed
* unless one of the following is true:
- * LK_FORCEUPGRADE is requested and some other process has already
- * requested a lock upgrade (returns EBUSY).
* LK_NOWAIT is set and a sleep would be required (returns EBUSY).
* LK_SLEEPFAIL is set and a sleep was done (returns ENOLCK).
* PCATCH is set in lock priority and a signal arrives (returns
* either EINTR or ERESTART if system calls is to be restarted).
* Non-null lock timeout and timeout expires (returns EWOULDBLOCK).
* A failed lock attempt always returns a non-zero error value. No lock
- * is held after an error return (in particular, a failed LK_UPGRADE
- * or LK_FORCEUPGRADE will have released its shared access lock).
+ * is held after an error return.
*/
/*