summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_mutex.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_mutex.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_mutex.c')
-rw-r--r--sys/kern/kern_mutex.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 0fd5d7e..b327ef8 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -91,6 +91,10 @@ __FBSDID("$FreeBSD$");
#ifdef DDB
static void db_show_mtx(struct lock_object *lock);
#endif
+static void lock_mtx(struct lock_object *lock, int how);
+static void lock_spin(struct lock_object *lock, int how);
+static int unlock_mtx(struct lock_object *lock);
+static int unlock_spin(struct lock_object *lock);
/*
* Lock classes for sleep and spin mutexes.
@@ -101,6 +105,8 @@ struct lock_class lock_class_mtx_sleep = {
#ifdef DDB
.lc_ddb_show = db_show_mtx,
#endif
+ .lc_lock = lock_mtx,
+ .lc_unlock = unlock_mtx,
};
struct lock_class lock_class_mtx_spin = {
.lc_name = "spin mutex",
@@ -108,6 +114,8 @@ struct lock_class lock_class_mtx_spin = {
#ifdef DDB
.lc_ddb_show = db_show_mtx,
#endif
+ .lc_lock = lock_spin,
+ .lc_unlock = unlock_spin,
};
/*
@@ -130,6 +138,38 @@ static inline void lock_profile_init(void)
static inline void lock_profile_init(void) {;}
#endif
+void
+lock_mtx(struct lock_object *lock, int how)
+{
+
+ mtx_lock((struct mtx *)lock);
+}
+
+void
+lock_spin(struct lock_object *lock, int how)
+{
+
+ panic("spin locks can only use msleep_spin");
+}
+
+int
+unlock_mtx(struct lock_object *lock)
+{
+ struct mtx *m;
+
+ m = (struct mtx *)lock;
+ mtx_assert(m, MA_OWNED | MA_NOTRECURSED);
+ mtx_unlock(m);
+ return (0);
+}
+
+int
+unlock_spin(struct lock_object *lock)
+{
+
+ panic("spin locks can only use msleep_spin");
+}
+
/*
* Function versions of the inlined __mtx_* macros. These are used by
* modules and can also be called from assembly language if needed.
OpenPOWER on IntegriCloud