Constify arguments for locking KPIs where possible.

This enables locking consumers to pass their own structures around as const and
be able to assert locks embedded into those structures.

Reviewed by:	ed, kib, jhb
This commit is contained in:
Pawel Jakub Dawidek 2011-11-16 21:51:17 +00:00
parent a9e3362a07
commit d576deedb5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=227588
17 changed files with 95 additions and 92 deletions

View File

@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 16, 2009
.Dd November 16, 2011
.Dt LOCK 9
.Os
.Sh NAME
@ -60,20 +60,20 @@
.Ft void
.Fn lockmgr_disown "struct lock *lkp"
.Ft void
.Fn lockmgr_printinfo "struct lock *lkp"
.Fn lockmgr_printinfo "const struct lock *lkp"
.Ft int
.Fn lockmgr_recursed "struct lock *lkp"
.Fn lockmgr_recursed "const struct lock *lkp"
.Ft int
.Fn lockmgr_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk"
.Ft int
.Fn lockmgr_waiters "struct lock *lkp"
.Fn lockmgr_waiters "const struct lock *lkp"
.Ft int
.Fn lockstatus "struct lock *lkp"
.Fn lockstatus "const struct lock *lkp"
.Pp
.Cd "options INVARIANTS"
.Cd "options INVARIANT_SUPPORT"
.Ft void
.Fn lockmgr_assert "struct lock *lkp" "int what"
.Fn lockmgr_assert "const struct lock *lkp" "int what"
.Sh DESCRIPTION
The
.Fn lockinit

View File

@ -28,7 +28,7 @@
.\" from BSDI $Id: mutex.4,v 1.1.2.3 1998/04/27 22:53:13 ewv Exp $
.\" $FreeBSD$
.\"
.Dd December 21, 2006
.Dd November 16, 2011
.Dt MUTEX 9
.Os
.Sh NAME
@ -83,16 +83,16 @@
.Ft int
.Fn mtx_sleep "void *chan" "struct mtx *mtx" "int priority" "const char *wmesg" "int timo"
.Ft int
.Fn mtx_initialized "struct mtx *mutex"
.Fn mtx_initialized "const struct mtx *mutex"
.Ft int
.Fn mtx_owned "struct mtx *mutex"
.Fn mtx_owned "const struct mtx *mutex"
.Ft int
.Fn mtx_recursed "struct mtx *mutex"
.Fn mtx_recursed "const struct mtx *mutex"
.Pp
.Cd "options INVARIANTS"
.Cd "options INVARIANT_SUPPORT"
.Ft void
.Fn mtx_assert "struct mtx *mutex" "int what"
.Fn mtx_assert "const struct mtx *mutex" "int what"
.In sys/kernel.h
.Fn MTX_SYSINIT "name" "struct mtx *mtx" "const char *description" "int opts"
.Sh DESCRIPTION

View File

@ -26,7 +26,7 @@
.\" $FreeBSD$
.\"
.\" Based on rwlock.9 man page
.Dd November 10, 2007
.Dd November 16, 2011
.Dt RMLOCK 9
.Os
.Sh NAME
@ -63,7 +63,7 @@
.Ft void
.Fn rm_wunlock "struct rmlock *rm"
.Ft int
.Fn rm_wowned "struct rmlock *rm"
.Fn rm_wowned "const struct rmlock *rm"
.In sys/kernel.h
.Fn RM_SYSINIT "name" "struct rmlock *rm" "const char *desc" "int opts"
.Sh DESCRIPTION
@ -208,7 +208,7 @@ This functions destroys a lock previously initialized with
The
.Fa rm
lock must be unlocked.
.It Fn rm_wowned "struct rmlock *rm"
.It Fn rm_wowned "const struct rmlock *rm"
This function returns a non-zero value if the current thread owns an
exclusive lock on
.Fa rm .

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd April 1, 2008
.Dd November 16, 2011
.Dt RWLOCK 9
.Os
.Sh NAME
@ -78,14 +78,14 @@
.Ft int
.Fn rw_sleep "void *chan" "struct rwlock *rw" "int priority" "const char *wmesg" "int timo"
.Ft int
.Fn rw_initialized "struct rwlock *rw"
.Fn rw_initialized "const struct rwlock *rw"
.Ft int
.Fn rw_wowned "struct rwlock *rw"
.Fn rw_wowned "const struct rwlock *rw"
.Pp
.Cd "options INVARIANTS"
.Cd "options INVARIANT_SUPPORT"
.Ft void
.Fn rw_assert "struct rwlock *rw" "int what"
.Fn rw_assert "const struct rwlock *rw" "int what"
.In sys/kernel.h
.Fn RW_SYSINIT "name" "struct rwlock *rw" "const char *desc"
.Sh DESCRIPTION
@ -231,7 +231,7 @@ while waiting for an event.
For more details on the parameters to this function,
see
.Xr sleep 9 .
.It Fn rw_initialized "struct rwlock *rw"
.It Fn rw_initialized "const struct rwlock *rw"
This function returns non-zero if
.Fa rw
has been initialized, and zero otherwise.
@ -241,11 +241,11 @@ This functions destroys a lock previously initialized with
The
.Fa rw
lock must be unlocked.
.It Fn rw_wowned "struct rwlock *rw"
.It Fn rw_wowned "const struct rwlock *rw"
This function returns a non-zero value if the current thread owns an
exclusive lock on
.Fa rw .
.It Fn rw_assert "struct rwlock *rw" "int what"
.It Fn rw_assert "const struct rwlock *rw" "int what"
This function allows assertions specified in
.Fa what
to be made about

View File

@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd May 28, 2009
.Dd November 16, 2011
.Dt SX 9
.Os
.Sh NAME
@ -88,12 +88,12 @@
.Ft "struct thread *"
.Fn sx_xholder "struct sx *sx"
.Ft int
.Fn sx_xlocked "struct sx *sx"
.Fn sx_xlocked "const struct sx *sx"
.Pp
.Cd "options INVARIANTS"
.Cd "options INVARIANT_SUPPORT"
.Ft void
.Fn sx_assert "struct sx *sx" "int what"
.Fn sx_assert "const struct sx *sx" "int what"
.In sys/kernel.h
.Fn SX_SYSINIT "name" "struct sx *sx" "const char *description"
.Sh DESCRIPTION

View File

@ -131,15 +131,16 @@ CTASSERT(LK_UNLOCKED == (LK_UNLOCKED &
#define lockmgr_xlocked(lk) \
(((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread)
static void assert_lockmgr(struct lock_object *lock, int how);
static void assert_lockmgr(const struct lock_object *lock, int how);
#ifdef DDB
static void db_show_lockmgr(struct lock_object *lock);
static void db_show_lockmgr(const struct lock_object *lock);
#endif
static void lock_lockmgr(struct lock_object *lock, int how);
static void lock_lockmgr(struct lock_object *lock, int how);
#ifdef KDTRACE_HOOKS
static int owner_lockmgr(struct lock_object *lock, struct thread **owner);
static int owner_lockmgr(const struct lock_object *lock,
struct thread **owner);
#endif
static int unlock_lockmgr(struct lock_object *lock);
static int unlock_lockmgr(struct lock_object *lock);
struct lock_class lock_class_lockmgr = {
.lc_name = "lockmgr",
@ -165,7 +166,7 @@ SYSCTL_UINT(_debug_lockmgr, OID_AUTO, loops, CTLFLAG_RW, &alk_loops, 0, "");
#endif
static __inline struct thread *
lockmgr_xholder(struct lock *lk)
lockmgr_xholder(const struct lock *lk)
{
uintptr_t x;
@ -335,7 +336,7 @@ wakeupshlk(struct lock *lk, const char *file, int line)
}
static void
assert_lockmgr(struct lock_object *lock, int what)
assert_lockmgr(const struct lock_object *lock, int what)
{
panic("lockmgr locks do not support assertions");
@ -357,7 +358,7 @@ unlock_lockmgr(struct lock_object *lock)
#ifdef KDTRACE_HOOKS
static int
owner_lockmgr(struct lock_object *lock, struct thread **owner)
owner_lockmgr(const struct lock_object *lock, struct thread **owner)
{
panic("lockmgr locks do not support owner inquiring");
@ -1260,7 +1261,7 @@ _lockmgr_disown(struct lock *lk, const char *file, int line)
}
void
lockmgr_printinfo(struct lock *lk)
lockmgr_printinfo(const struct lock *lk)
{
struct thread *td;
uintptr_t x;
@ -1289,7 +1290,7 @@ lockmgr_printinfo(struct lock *lk)
}
int
lockstatus(struct lock *lk)
lockstatus(const struct lock *lk)
{
uintptr_t v, x;
int ret;
@ -1319,7 +1320,7 @@ FEATURE(invariant_support,
#endif
void
_lockmgr_assert(struct lock *lk, int what, const char *file, int line)
_lockmgr_assert(const struct lock *lk, int what, const char *file, int line)
{
int slocked = 0;
@ -1412,12 +1413,12 @@ lockmgr_chain(struct thread *td, struct thread **ownerp)
}
static void
db_show_lockmgr(struct lock_object *lock)
db_show_lockmgr(const struct lock_object *lock)
{
struct thread *td;
struct lock *lk;
const struct lock *lk;
lk = (struct lock *)lock;
lk = (const struct lock *)lock;
db_printf(" state: ");
if (lk->lk_lock == LK_UNLOCKED)

View File

@ -85,14 +85,15 @@ __FBSDID("$FreeBSD$");
#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
static void assert_mtx(struct lock_object *lock, int what);
static void assert_mtx(const struct lock_object *lock, int what);
#ifdef DDB
static void db_show_mtx(struct lock_object *lock);
static void db_show_mtx(const 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);
#ifdef KDTRACE_HOOKS
static int owner_mtx(struct lock_object *lock, struct thread **owner);
static int owner_mtx(const struct lock_object *lock,
struct thread **owner);
#endif
static int unlock_mtx(struct lock_object *lock);
static int unlock_spin(struct lock_object *lock);
@ -134,10 +135,10 @@ struct mtx blocked_lock;
struct mtx Giant;
void
assert_mtx(struct lock_object *lock, int what)
assert_mtx(const struct lock_object *lock, int what)
{
mtx_assert((struct mtx *)lock, what);
mtx_assert((const struct mtx *)lock, what);
}
void
@ -174,9 +175,9 @@ unlock_spin(struct lock_object *lock)
#ifdef KDTRACE_HOOKS
int
owner_mtx(struct lock_object *lock, struct thread **owner)
owner_mtx(const struct lock_object *lock, struct thread **owner)
{
struct mtx *m = (struct mtx *)lock;
const struct mtx *m = (const struct mtx *)lock;
*owner = mtx_owner(m);
return (mtx_unowned(m) == 0);
@ -693,7 +694,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
*/
#ifdef INVARIANT_SUPPORT
void
_mtx_assert(struct mtx *m, int what, const char *file, int line)
_mtx_assert(const struct mtx *m, int what, const char *file, int line)
{
if (panicstr != NULL || dumping)
@ -871,12 +872,12 @@ mutex_init(void)
#ifdef DDB
void
db_show_mtx(struct lock_object *lock)
db_show_mtx(const struct lock_object *lock)
{
struct thread *td;
struct mtx *m;
const struct mtx *m;
m = (struct mtx *)lock;
m = (const struct mtx *)lock;
db_printf(" flags: {");
if (LOCK_CLASS(lock) == &lock_class_mtx_spin)

View File

@ -69,10 +69,10 @@ static __inline void compiler_memory_barrier(void) {
__asm __volatile("":::"memory");
}
static void assert_rm(struct lock_object *lock, int what);
static void assert_rm(const struct lock_object *lock, int what);
static void lock_rm(struct lock_object *lock, int how);
#ifdef KDTRACE_HOOKS
static int owner_rm(struct lock_object *lock, struct thread **owner);
static int owner_rm(const struct lock_object *lock, struct thread **owner);
#endif
static int unlock_rm(struct lock_object *lock);
@ -93,7 +93,7 @@ struct lock_class lock_class_rm = {
};
static void
assert_rm(struct lock_object *lock, int what)
assert_rm(const struct lock_object *lock, int what)
{
panic("assert_rm called");
@ -115,7 +115,7 @@ unlock_rm(struct lock_object *lock)
#ifdef KDTRACE_HOOKS
static int
owner_rm(struct lock_object *lock, struct thread **owner)
owner_rm(const struct lock_object *lock, struct thread **owner)
{
panic("owner_rm called");
@ -227,7 +227,7 @@ rm_destroy(struct rmlock *rm)
}
int
rm_wowned(struct rmlock *rm)
rm_wowned(const struct rmlock *rm)
{
if (rm->lock_object.lo_flags & RM_SLEEPABLE)

View File

@ -67,12 +67,12 @@ SYSCTL_INT(_debug_rwlock, OID_AUTO, loops, CTLFLAG_RW, &rowner_loops, 0, "");
#ifdef DDB
#include <ddb/ddb.h>
static void db_show_rwlock(struct lock_object *lock);
static void db_show_rwlock(const struct lock_object *lock);
#endif
static void assert_rw(struct lock_object *lock, int what);
static void assert_rw(const struct lock_object *lock, int what);
static void lock_rw(struct lock_object *lock, int how);
#ifdef KDTRACE_HOOKS
static int owner_rw(struct lock_object *lock, struct thread **owner);
static int owner_rw(const struct lock_object *lock, struct thread **owner);
#endif
static int unlock_rw(struct lock_object *lock);
@ -121,10 +121,10 @@ struct lock_class lock_class_rw = {
#endif
void
assert_rw(struct lock_object *lock, int what)
assert_rw(const struct lock_object *lock, int what)
{
rw_assert((struct rwlock *)lock, what);
rw_assert((const struct rwlock *)lock, what);
}
void
@ -157,9 +157,9 @@ unlock_rw(struct lock_object *lock)
#ifdef KDTRACE_HOOKS
int
owner_rw(struct lock_object *lock, struct thread **owner)
owner_rw(const struct lock_object *lock, struct thread **owner)
{
struct rwlock *rw = (struct rwlock *)lock;
const struct rwlock *rw = (const struct rwlock *)lock;
uintptr_t x = rw->rw_lock;
*owner = rw_wowner(rw);
@ -223,7 +223,7 @@ rw_sysinit_flags(void *arg)
}
int
rw_wowned(struct rwlock *rw)
rw_wowned(const struct rwlock *rw)
{
return (rw_wowner(rw) == curthread);
@ -1011,7 +1011,7 @@ _rw_downgrade(struct rwlock *rw, const char *file, int line)
* thread owns an rlock.
*/
void
_rw_assert(struct rwlock *rw, int what, const char *file, int line)
_rw_assert(const struct rwlock *rw, int what, const char *file, int line)
{
if (panicstr != NULL)
@ -1084,12 +1084,12 @@ _rw_assert(struct rwlock *rw, int what, const char *file, int line)
#ifdef DDB
void
db_show_rwlock(struct lock_object *lock)
db_show_rwlock(const struct lock_object *lock)
{
struct rwlock *rw;
const struct rwlock *rw;
struct thread *td;
rw = (struct rwlock *)lock;
rw = (const struct rwlock *)lock;
db_printf(" state: ");
if (rw->rw_lock == RW_UNLOCKED)

View File

@ -105,13 +105,13 @@ CTASSERT((SX_NOADAPTIVE & LO_CLASSFLAGS) == SX_NOADAPTIVE);
#define sx_recurse lock_object.lo_data
#define sx_recursed(sx) ((sx)->sx_recurse != 0)
static void assert_sx(struct lock_object *lock, int what);
static void assert_sx(const struct lock_object *lock, int what);
#ifdef DDB
static void db_show_sx(struct lock_object *lock);
static void db_show_sx(const struct lock_object *lock);
#endif
static void lock_sx(struct lock_object *lock, int how);
#ifdef KDTRACE_HOOKS
static int owner_sx(struct lock_object *lock, struct thread **owner);
static int owner_sx(const struct lock_object *lock, struct thread **owner);
#endif
static int unlock_sx(struct lock_object *lock);
@ -142,10 +142,10 @@ SYSCTL_UINT(_debug_sx, OID_AUTO, loops, CTLFLAG_RW, &asx_loops, 0, "");
#endif
void
assert_sx(struct lock_object *lock, int what)
assert_sx(const struct lock_object *lock, int what)
{
sx_assert((struct sx *)lock, what);
sx_assert((const struct sx *)lock, what);
}
void
@ -178,9 +178,9 @@ unlock_sx(struct lock_object *lock)
#ifdef KDTRACE_HOOKS
int
owner_sx(struct lock_object *lock, struct thread **owner)
owner_sx(const struct lock_object *lock, struct thread **owner)
{
struct sx *sx = (struct sx *)lock;
const struct sx *sx = (const struct sx *)lock;
uintptr_t x = sx->sx_lock;
*owner = (struct thread *)SX_OWNER(x);
@ -1005,7 +1005,7 @@ _sx_sunlock_hard(struct sx *sx, const char *file, int line)
* thread owns an slock.
*/
void
_sx_assert(struct sx *sx, int what, const char *file, int line)
_sx_assert(const struct sx *sx, int what, const char *file, int line)
{
#ifndef WITNESS
int slocked = 0;
@ -1088,12 +1088,12 @@ _sx_assert(struct sx *sx, int what, const char *file, int line)
#ifdef DDB
static void
db_show_sx(struct lock_object *lock)
db_show_sx(const struct lock_object *lock)
{
struct thread *td;
struct sx *sx;
const struct sx *sx;
sx = (struct sx *)lock;
sx = (const struct sx *)lock;
db_printf(" state: ");
if (sx->sx_lock == SX_LOCK_UNLOCKED)

View File

@ -332,7 +332,7 @@ static void depart(struct witness *w);
static struct witness *enroll(const char *description,
struct lock_class *lock_class);
static struct lock_instance *find_instance(struct lock_list_entry *list,
struct lock_object *lock);
const struct lock_object *lock);
static int isitmychild(struct witness *parent, struct witness *child);
static int isitmydescendant(struct witness *parent, struct witness *child);
static void itismychild(struct witness *parent, struct witness *child);
@ -2063,7 +2063,7 @@ witness_lock_list_free(struct lock_list_entry *lle)
}
static struct lock_instance *
find_instance(struct lock_list_entry *list, struct lock_object *lock)
find_instance(struct lock_list_entry *list, const struct lock_object *lock)
{
struct lock_list_entry *lle;
struct lock_instance *instance;
@ -2210,7 +2210,8 @@ witness_restore(struct lock_object *lock, const char *file, int line)
}
void
witness_assert(struct lock_object *lock, int flags, const char *file, int line)
witness_assert(const struct lock_object *lock, int flags, const char *file,
int line)
{
#ifdef INVARIANT_SUPPORT
struct lock_instance *instance;

View File

@ -58,10 +58,10 @@ 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_assert)(const struct lock_object *lock, int what);
void (*lc_ddb_show)(const struct lock_object *lock);
void (*lc_lock)(struct lock_object *lock, int how);
int (*lc_owner)(struct lock_object *lock, struct thread **owner);
int (*lc_owner)(const struct lock_object *lock, struct thread **owner);
int (*lc_unlock)(struct lock_object *lock);
};
@ -215,7 +215,7 @@ void witness_restore(struct lock_object *, const char *, int);
int witness_list_locks(struct lock_list_entry **,
int (*)(const char *, ...));
int witness_warn(int, struct lock_object *, const char *, ...);
void witness_assert(struct lock_object *, int, const char *, int);
void witness_assert(const struct lock_object *, int, const char *, int);
void witness_display_spinlock(struct lock_object *, struct thread *,
int (*)(const char *, ...));
int witness_line(struct lock_object *);

View File

@ -69,7 +69,7 @@ struct thread;
int __lockmgr_args(struct lock *lk, u_int flags, struct lock_object *ilk,
const char *wmesg, int prio, int timo, const char *file, int line);
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
void _lockmgr_assert(struct lock *lk, int what, const char *file, int line);
void _lockmgr_assert(const struct lock *lk, int what, const char *file, int line);
#endif
void _lockmgr_disown(struct lock *lk, const char *file, int line);
@ -82,8 +82,8 @@ void lockinit(struct lock *lk, int prio, const char *wmesg, int timo,
#ifdef DDB
int lockmgr_chain(struct thread *td, struct thread **ownerp);
#endif
void lockmgr_printinfo(struct lock *lk);
int lockstatus(struct lock *lk);
void lockmgr_printinfo(const struct lock *lk);
int lockstatus(const struct lock *lk);
/*
* As far as the ilk can be a static NULL pointer these functions need a

View File

@ -105,7 +105,7 @@ void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file,
void _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file,
int line);
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
void _mtx_assert(struct mtx *m, int what, const char *file, int line);
void _mtx_assert(const struct mtx *m, int what, const char *file, int line);
#endif
void _thread_lock_flags(struct thread *, int, const char *, int);

View File

@ -49,7 +49,7 @@
void rm_init(struct rmlock *rm, const char *name);
void rm_init_flags(struct rmlock *rm, const char *name, int opts);
void rm_destroy(struct rmlock *rm);
int rm_wowned(struct rmlock *rm);
int rm_wowned(const struct rmlock *rm);
void rm_sysinit(void *arg);
void rm_sysinit_flags(void *arg);

View File

@ -127,7 +127,7 @@ void rw_init_flags(struct rwlock *rw, const char *name, int opts);
void rw_destroy(struct rwlock *rw);
void rw_sysinit(void *arg);
void rw_sysinit_flags(void *arg);
int rw_wowned(struct rwlock *rw);
int rw_wowned(const struct rwlock *rw);
void _rw_wlock(struct rwlock *rw, const char *file, int line);
int _rw_try_wlock(struct rwlock *rw, const char *file, int line);
void _rw_wunlock(struct rwlock *rw, const char *file, int line);
@ -141,7 +141,7 @@ void _rw_wunlock_hard(struct rwlock *rw, uintptr_t tid, const char *file,
int _rw_try_upgrade(struct rwlock *rw, const char *file, int line);
void _rw_downgrade(struct rwlock *rw, const char *file, int line);
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
void _rw_assert(struct rwlock *rw, int what, const char *file, int line);
void _rw_assert(const struct rwlock *rw, int what, const char *file, int line);
#endif
/*

View File

@ -109,7 +109,7 @@ void _sx_xunlock_hard(struct sx *sx, uintptr_t tid, const char *file, int
line);
void _sx_sunlock_hard(struct sx *sx, const char *file, int line);
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
void _sx_assert(struct sx *sx, int what, const char *file, int line);
void _sx_assert(const struct sx *sx, int what, const char *file, int line);
#endif
#ifdef DDB
int sx_chain(struct thread *td, struct thread **ownerp);