Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/kern_mutex.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/kern_mutex.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.63 retrieving revision 1.67 diff -u -p -r1.63 -r1.67 --- src/sys/kern/kern_mutex.c 2016/07/07 06:55:43 1.63 +++ src/sys/kern/kern_mutex.c 2017/09/16 23:55:33 1.67 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_mutex.c,v 1.63 2016/07/07 06:55:43 msaitoh Exp $ */ +/* $NetBSD: kern_mutex.c,v 1.67 2017/09/16 23:55:33 christos Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ #define __MUTEX_PRIVATE #include -__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.63 2016/07/07 06:55:43 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.67 2017/09/16 23:55:33 christos Exp $"); #include #include @@ -75,6 +75,9 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c #define MUTEX_WANTLOCK(mtx) \ LOCKDEBUG_WANTLOCK(MUTEX_DEBUG_P(mtx), (mtx), \ (uintptr_t)__builtin_return_address(0), 0) +#define MUTEX_TESTLOCK(mtx) \ + LOCKDEBUG_WANTLOCK(MUTEX_DEBUG_P(mtx), (mtx), \ + (uintptr_t)__builtin_return_address(0), -1) #define MUTEX_LOCKED(mtx) \ LOCKDEBUG_LOCKED(MUTEX_DEBUG_P(mtx), (mtx), NULL, \ (uintptr_t)__builtin_return_address(0), 0) @@ -82,7 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c LOCKDEBUG_UNLOCKED(MUTEX_DEBUG_P(mtx), (mtx), \ (uintptr_t)__builtin_return_address(0), 0) #define MUTEX_ABORT(mtx, msg) \ - mutex_abort(mtx, __func__, msg) + mutex_abort(__func__, __LINE__, mtx, msg) #if defined(LOCKDEBUG) @@ -261,8 +264,9 @@ __strong_alias(mutex_spin_enter,mutex_ve __strong_alias(mutex_spin_exit,mutex_vector_exit); #endif -static void mutex_abort(kmutex_t *, const char *, const char *); -static void mutex_dump(volatile void *); +static void mutex_abort(const char *, size_t, const kmutex_t *, + const char *); +static void mutex_dump(const volatile void *); lockops_t mutex_spin_lockops = { "Mutex", @@ -290,9 +294,9 @@ syncobj_t mutex_syncobj = { * Dump the contents of a mutex structure. */ void -mutex_dump(volatile void *cookie) +mutex_dump(const volatile void *cookie) { - volatile kmutex_t *mtx = cookie; + const volatile kmutex_t *mtx = cookie; printf_nolog("owner field : %#018lx wait/spin: %16d/%d\n", (long)MUTEX_OWNER(mtx->mtx_owner), MUTEX_HAS_WAITERS(mtx), @@ -307,11 +311,11 @@ mutex_dump(volatile void *cookie) * we ask the compiler to not inline it. */ void __noinline -mutex_abort(kmutex_t *mtx, const char *func, const char *msg) +mutex_abort(const char *func, size_t line, const kmutex_t *mtx, const char *msg) { - LOCKDEBUG_ABORT(mtx, (MUTEX_SPIN_P(mtx) ? - &mutex_spin_lockops : &mutex_adaptive_lockops), func, msg); + LOCKDEBUG_ABORT(func, line, mtx, (MUTEX_SPIN_P(mtx) ? + &mutex_spin_lockops : &mutex_adaptive_lockops), msg); } /* @@ -802,7 +806,7 @@ mutex_wakeup(kmutex_t *mtx) * holds the mutex. */ int -mutex_owned(kmutex_t *mtx) +mutex_owned(const kmutex_t *mtx) { if (mtx == NULL) @@ -823,7 +827,7 @@ mutex_owned(kmutex_t *mtx) * priority inheritance. */ lwp_t * -mutex_owner(kmutex_t *mtx) +mutex_owner(const kmutex_t *mtx) { MUTEX_ASSERT(mtx, MUTEX_ADAPTIVE_P(mtx)); @@ -831,6 +835,23 @@ mutex_owner(kmutex_t *mtx) } /* + * mutex_ownable: + * + * When compiled with DEBUG and LOCKDEBUG defined, ensure that + * the mutex is available. We cannot use !mutex_owned() since + * that won't work correctly for spin mutexes. + */ +int +mutex_ownable(const kmutex_t *mtx) +{ + +#ifdef LOCKDEBUG + MUTEX_TESTLOCK(mtx); +#endif + return 1; +} + +/* * mutex_tryenter: * * Try to acquire the mutex; return non-zero if we did.