From d278a7f9ba33ea5536ee8db25b82c513bbe6a970 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 11 Mar 2003 20:54:37 +0000 Subject: [PATCH] Do the lock order check skip for the LOP_TRYLOCK case after the check for recursing on a lock instead of before. This fixes a bug where WITNESS could get a little confused if you did an sx_tryslock() on a sx lock that you already had an slock on. WITNESS would still function correctly but it could result in weirdness in the output of 'show locks'. This also makes it possible for mtx_trylock() to recurse on a lock. --- sys/kern/subr_witness.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index 0453c933a7e9..47642b9bcbe6 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -555,14 +555,6 @@ witness_lock(struct lock_object *lock, int flags, const char *file, int line) } else lock_list = PCPU_PTR(spinlocks); - /* - * Try locks do not block if they fail to acquire the lock, thus - * there is no danger of deadlocks or of switching while holding a - * spin lock if we acquire a lock via a try operation. - */ - if (flags & LOP_TRYLOCK) - goto out; - /* * Is this the first lock acquired? If so, then no order checking * is needed. @@ -608,6 +600,14 @@ witness_lock(struct lock_object *lock, int flags, const char *file, int line) return; } + /* + * Try locks do not block if they fail to acquire the lock, thus + * there is no danger of deadlocks or of switching while holding a + * spin lock if we acquire a lock via a try operation. + */ + if (flags & LOP_TRYLOCK) + goto out; + /* * Check for duplicate locks of the same type. Note that we only * have to check for this on the last lock we just acquired. Any