summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sx.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-03-09 16:27:11 +0000
committerjhb <jhb@FreeBSD.org>2007-03-09 16:27:11 +0000
commit60ad130f466f4ce8bb90b4d47775516afbfb2e48 (patch)
tree71366da8c5df1e7210aad9d816166233c0107eff /sys/kern/kern_sx.c
parentb03e9e93edda2ff558f1eb141e812c32a2931dc2 (diff)
downloadFreeBSD-src-60ad130f466f4ce8bb90b4d47775516afbfb2e48.zip
FreeBSD-src-60ad130f466f4ce8bb90b4d47775516afbfb2e48.tar.gz
Add two new function pointers 'lc_lock' and 'lc_unlock' to lock classes.
These functions are intended to be used to drop a lock and then reacquire it when doing an sleep such as msleep(9). Both functions accept a 'struct lock_object *' as their first parameter. The 'lc_unlock' function returns an integer that is then passed as the second paramter to the subsequent 'lc_lock' function. This can be used to communicate state. For example, sx locks and rwlocks use this to indicate if the lock was share/read locked vs exclusive/write locked. Currently, spin mutexes and lockmgr locks do not provide working lc_lock and lc_unlock functions.
Diffstat (limited to 'sys/kern/kern_sx.c')
-rw-r--r--sys/kern/kern_sx.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index d41f94e..5499171 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -54,6 +54,8 @@ __FBSDID("$FreeBSD$");
static void db_show_sx(struct lock_object *lock);
#endif
+static void lock_sx(struct lock_object *lock, int how);
+static int unlock_sx(struct lock_object *lock);
struct lock_class lock_class_sx = {
.lc_name = "sx",
@@ -61,6 +63,8 @@ struct lock_class lock_class_sx = {
#ifdef DDB
.lc_ddb_show = db_show_sx,
#endif
+ .lc_lock = lock_sx,
+ .lc_unlock = unlock_sx,
};
#ifndef INVARIANTS
@@ -68,6 +72,34 @@ struct lock_class lock_class_sx = {
#endif
void
+lock_sx(struct lock_object *lock, int how)
+{
+ struct sx *sx;
+
+ sx = (struct sx *)lock;
+ if (how)
+ sx_xlock(sx);
+ else
+ sx_slock(sx);
+}
+
+int
+unlock_sx(struct lock_object *lock)
+{
+ struct sx *sx;
+
+ sx = (struct sx *)lock;
+ sx_assert(sx, SX_LOCKED | LA_NOTRECURSED);
+ if (sx_xlocked(sx)) {
+ sx_xunlock(sx);
+ return (1);
+ } else {
+ sx_sunlock(sx);
+ return (0);
+ }
+}
+
+void
sx_sysinit(void *arg)
{
struct sx_args *sargs = arg;
@@ -348,6 +380,7 @@ _sx_assert(struct sx *sx, int what, const char *file, int line)
return;
switch (what) {
case SX_LOCKED:
+ case SX_LOCKED | LA_NOTRECURSED:
case SX_SLOCKED:
#ifdef WITNESS
witness_assert(&sx->sx_object, what, file, line);
OpenPOWER on IntegriCloud