Expand lock class with the "virtual" function lc_assert which will offer
an unified way for all the lock primitives to express lock assertions. Currenty, lockmgrs and rmlocks don't have assertions, so just panic in that case. This will be a base for more callout improvements. Ok'ed by: jhb, jeff
This commit is contained in:
parent
9dbec8e7df
commit
bfc761fdba
@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/stack.h>
|
||||
#endif
|
||||
|
||||
static void assert_lockmgr(struct lock_object *lock, int what);
|
||||
#ifdef DDB
|
||||
#include <ddb/ddb.h>
|
||||
static void db_show_lockmgr(struct lock_object *lock);
|
||||
@ -70,6 +71,7 @@ static int unlock_lockmgr(struct lock_object *lock);
|
||||
struct lock_class lock_class_lockmgr = {
|
||||
.lc_name = "lockmgr",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE,
|
||||
.lc_assert = assert_lockmgr,
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_lockmgr,
|
||||
#endif
|
||||
@ -82,6 +84,13 @@ struct lock_class lock_class_lockmgr = {
|
||||
* Locks provide shared/exclusive sychronization.
|
||||
*/
|
||||
|
||||
void
|
||||
assert_lockmgr(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
panic("lockmgr locks do not support assertions");
|
||||
}
|
||||
|
||||
void
|
||||
lock_lockmgr(struct lock_object *lock, int how)
|
||||
{
|
||||
|
@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
|
||||
|
||||
static void assert_mtx(struct lock_object *lock, int what);
|
||||
#ifdef DDB
|
||||
static void db_show_mtx(struct lock_object *lock);
|
||||
#endif
|
||||
@ -98,6 +99,7 @@ static int unlock_spin(struct lock_object *lock);
|
||||
struct lock_class lock_class_mtx_sleep = {
|
||||
.lc_name = "sleep mutex",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE,
|
||||
.lc_assert = assert_mtx,
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_mtx,
|
||||
#endif
|
||||
@ -107,6 +109,7 @@ struct lock_class lock_class_mtx_sleep = {
|
||||
struct lock_class lock_class_mtx_spin = {
|
||||
.lc_name = "spin mutex",
|
||||
.lc_flags = LC_SPINLOCK | LC_RECURSABLE,
|
||||
.lc_assert = assert_mtx,
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_mtx,
|
||||
#endif
|
||||
@ -134,6 +137,13 @@ static inline void lock_profile_init(void)
|
||||
static inline void lock_profile_init(void) {;}
|
||||
#endif
|
||||
|
||||
void
|
||||
assert_mtx(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
mtx_assert((struct mtx *)lock, what);
|
||||
}
|
||||
|
||||
void
|
||||
lock_mtx(struct lock_object *lock, int how)
|
||||
{
|
||||
|
@ -71,12 +71,14 @@ static __inline void compiler_memory_barrier(void) {
|
||||
__asm __volatile("":::"memory");
|
||||
}
|
||||
|
||||
static void assert_rm(struct lock_object *lock, int what);
|
||||
static void lock_rm(struct lock_object *lock, int how);
|
||||
static int unlock_rm(struct lock_object *lock);
|
||||
|
||||
struct lock_class lock_class_rm = {
|
||||
.lc_name = "rm",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE,
|
||||
.lc_assert = assert_rm,
|
||||
#if 0
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_rwlock,
|
||||
@ -86,6 +88,13 @@ struct lock_class lock_class_rm = {
|
||||
.lc_unlock = unlock_rm,
|
||||
};
|
||||
|
||||
static void
|
||||
assert_rm(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
panic("assert_rm called");
|
||||
}
|
||||
|
||||
static void
|
||||
lock_rm(struct lock_object *lock, int how) {
|
||||
panic("lock_rm called");
|
||||
|
@ -59,12 +59,14 @@ CTASSERT((RW_RECURSE & LO_CLASSFLAGS) == RW_RECURSE);
|
||||
|
||||
static void db_show_rwlock(struct lock_object *lock);
|
||||
#endif
|
||||
static void assert_rw(struct lock_object *lock, int what);
|
||||
static void lock_rw(struct lock_object *lock, int how);
|
||||
static int unlock_rw(struct lock_object *lock);
|
||||
|
||||
struct lock_class lock_class_rw = {
|
||||
.lc_name = "rw",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE,
|
||||
.lc_assert = assert_rw,
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_rwlock,
|
||||
#endif
|
||||
@ -102,6 +104,13 @@ struct lock_class lock_class_rw = {
|
||||
#define _rw_assert(rw, what, file, line)
|
||||
#endif
|
||||
|
||||
void
|
||||
assert_rw(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
rw_assert((struct rwlock *)lock, what);
|
||||
}
|
||||
|
||||
void
|
||||
lock_rw(struct lock_object *lock, int how)
|
||||
{
|
||||
|
@ -103,6 +103,7 @@ CTASSERT(((SX_ADAPTIVESPIN | SX_RECURSE) & LO_CLASSFLAGS) ==
|
||||
*/
|
||||
#define sx_recursed(sx) ((sx)->sx_recurse != 0)
|
||||
|
||||
static void assert_sx(struct lock_object *lock, int what);
|
||||
#ifdef DDB
|
||||
static void db_show_sx(struct lock_object *lock);
|
||||
#endif
|
||||
@ -112,6 +113,7 @@ static int unlock_sx(struct lock_object *lock);
|
||||
struct lock_class lock_class_sx = {
|
||||
.lc_name = "sx",
|
||||
.lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE,
|
||||
.lc_assert = assert_sx,
|
||||
#ifdef DDB
|
||||
.lc_ddb_show = db_show_sx,
|
||||
#endif
|
||||
@ -123,6 +125,13 @@ struct lock_class lock_class_sx = {
|
||||
#define _sx_assert(sx, what, file, line)
|
||||
#endif
|
||||
|
||||
void
|
||||
assert_sx(struct lock_object *lock, int what)
|
||||
{
|
||||
|
||||
sx_assert((struct sx *)lock, what);
|
||||
}
|
||||
|
||||
void
|
||||
lock_sx(struct lock_object *lock, int how)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ struct thread;
|
||||
struct lock_class {
|
||||
const char *lc_name;
|
||||
u_int lc_flags;
|
||||
void (*lc_assert)(struct lock_object *lock, int what);
|
||||
void (*lc_ddb_show)(struct lock_object *lock);
|
||||
void (*lc_lock)(struct lock_object *lock, int how);
|
||||
int (*lc_unlock)(struct lock_object *lock);
|
||||
|
Loading…
x
Reference in New Issue
Block a user