diff options
author | pjd <pjd@FreeBSD.org> | 2011-11-16 21:51:17 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-11-16 21:51:17 +0000 |
commit | a3e664d830a8cf18b39de7e24de3b6945e09d802 (patch) | |
tree | 0f843eda4349e58b83edfddade168cfeeb527616 /sys/kern | |
parent | 8f7796960e5324d9006d05ab644c421a3428a863 (diff) | |
download | FreeBSD-src-a3e664d830a8cf18b39de7e24de3b6945e09d802.zip FreeBSD-src-a3e664d830a8cf18b39de7e24de3b6945e09d802.tar.gz |
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
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_lock.c | 29 | ||||
-rw-r--r-- | sys/kern/kern_mutex.c | 23 | ||||
-rw-r--r-- | sys/kern/kern_rmlock.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_rwlock.c | 24 | ||||
-rw-r--r-- | sys/kern/kern_sx.c | 22 | ||||
-rw-r--r-- | sys/kern/subr_witness.c | 7 |
6 files changed, 59 insertions, 56 deletions
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index ddd55bb..459811e 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -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) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 041b480..7666116 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -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) diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c index 1c7337d..181825a 100644 --- a/sys/kern/kern_rmlock.c +++ b/sys/kern/kern_rmlock.c @@ -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) diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 1037f34..a4d3e96 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -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 @@ out: * 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) diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 1e4430a..9230beb 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -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) diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index 130c7b3..bbf9a97 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -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; |