That's all fine, until someone uses this not for KASSERT, but as part of
their logic.
while(!rw_read_held(lock)) {
do something;
}
I think this kind of thing fleads to people building "try" APIs.
Martin Pieuchot <[email protected]> wrote:
> Simple diff below to add the rw_lock_held() as well as a read & write
> version.
>
> This allows us to reduce the difference with NetBSD in UVM by adding the
> following checks:
>
> KASSERT(rw_write_held(amap->am_lock));
>
> ok?
>
> Index: sys/rwlock.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/rwlock.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 rwlock.h
> --- sys/rwlock.h 16 Jul 2019 01:40:49 -0000 1.26
> +++ sys/rwlock.h 7 Dec 2020 18:22:03 -0000
> @@ -168,6 +168,11 @@ int rw_enter(struct rwlock *, int);
> void rw_exit(struct rwlock *);
> int rw_status(struct rwlock *);
>
> +#define rw_read_held(rwl) (rw_status(rwl) == RW_READ)
> +#define rw_write_held(rwl) (rw_status(rwl) == RW_WRITE)
> +#define rw_lock_held(rwl) (rw_write_held(rwl) ||
> rw_read_held(rwl))
> +
> +
> void _rrw_init_flags(struct rrwlock *, const char *, int,
> const struct lock_type *);
> int rrw_enter(struct rrwlock *, int);
>