summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sx.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2004-01-28 20:39:57 +0000
committerjhb <jhb@FreeBSD.org>2004-01-28 20:39:57 +0000
commit7c38a96e26ea6ac5011842d1d51cd51ed70eb958 (patch)
treed3c375a1a6a32f2ee6a61b1e0480fe131cb8ae7f /sys/kern/kern_sx.c
parent3678d31f1762251640dd504e43143335331df1d0 (diff)
downloadFreeBSD-src-7c38a96e26ea6ac5011842d1d51cd51ed70eb958.zip
FreeBSD-src-7c38a96e26ea6ac5011842d1d51cd51ed70eb958.tar.gz
Rework witness_lock() to make it slightly more useful and flexible.
- witness_lock() is split into two pieces: witness_checkorder() and witness_lock(). Witness_checkorder() determines if acquiring a specified lock at the time it is called would result in a lock order. It optionally adds a new lock order relationship as well. witness_lock() updates witness's data structures to assume that a lock has been acquired by stick a new lock instance in the appropriate lock instance list. - The mutex and sx lock functions now call checkorder() prior to trying to acquire a lock and continue to call witness_lock() after the acquire is completed. This will let witness catch a deadlock before it happens rather than trying to do so after the threads have deadlocked (i.e. never actually report it). - A new function witness_defineorder() has been added that adds a lock order between two locks at runtime without having to acquire the locks. If the lock order cannot be added it will return an error. This function is available to programmers via the WITNESS_DEFINEORDER() macro which accepts either two mutexes or two sx locks as its arguments. - A few simple wrapper macros were added to allow developers to call witness_checkorder() anywhere as a way of enforcing locking assertions in code that might acquire a certain lock in some situations. The macros are: witness_check_{mutex,shared_sx,exclusive_sx} and take an appropriate lock as the sole argument. - The code to remove a lock instance from a lock list in witness_unlock() was unnested by using a goto to vastly improve the readability of this function.
Diffstat (limited to 'sys/kern/kern_sx.c')
-rw-r--r--sys/kern/kern_sx.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index 4256b0a..fd723ed 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -112,6 +112,7 @@ _sx_slock(struct sx *sx, const char *file, int line)
KASSERT(sx->sx_xholder != curthread,
("%s (%s): slock while xlock is held @ %s:%d\n", __func__,
sx->sx_object.lo_name, file, line));
+ WITNESS_CHECKORDER(&sx->sx_object, LOP_NEWORDER, file, line);
/*
* Loop in case we lose the race for lock acquisition.
@@ -165,6 +166,8 @@ _sx_xlock(struct sx *sx, const char *file, int line)
KASSERT(sx->sx_xholder != curthread,
("%s (%s): xlock already held @ %s:%d", __func__,
sx->sx_object.lo_name, file, line));
+ WITNESS_CHECKORDER(&sx->sx_object, LOP_NEWORDER | LOP_EXCLUSIVE, file,
+ line);
/* Loop in case we lose the race for lock acquisition. */
while (sx->sx_cnt != 0) {
OpenPOWER on IntegriCloud