On Tue, Mar 15, 2022 at 02:12:43PM +0000, Visa Hankala wrote:
> Make kqueue use the refcnt API.
>
> OK?
OK bluhm@
> Index: sys/kern/kern_event.c
> ===================================================================
> RCS file: src/sys/kern/kern_event.c,v
> retrieving revision 1.183
> diff -u -p -r1.183 kern_event.c
> --- sys/kern/kern_event.c 22 Feb 2022 01:15:01 -0000 1.183
> +++ sys/kern/kern_event.c 15 Mar 2022 13:43:20 -0000
> @@ -199,7 +199,7 @@ const struct filterops *const sysfilt_op
> void
> KQREF(struct kqueue *kq)
> {
> - atomic_inc_int(&kq->kq_refs);
> + refcnt_take(&kq->kq_refcnt);
> }
>
> void
> @@ -207,7 +207,7 @@ KQRELE(struct kqueue *kq)
> {
> struct filedesc *fdp;
>
> - if (atomic_dec_int_nv(&kq->kq_refs) > 0)
> + if (refcnt_rele(&kq->kq_refcnt) == 0)
> return;
>
> fdp = kq->kq_fdp;
> @@ -837,7 +837,7 @@ kqpoll_exit(void)
>
> kqueue_purge(p, p->p_kq);
> kqueue_terminate(p, p->p_kq);
> - KASSERT(p->p_kq->kq_refs == 1);
> + KASSERT(p->p_kq->kq_refcnt.r_refs == 1);
> KQRELE(p->p_kq);
> p->p_kq = NULL;
> }
> @@ -848,7 +848,7 @@ kqueue_alloc(struct filedesc *fdp)
> struct kqueue *kq;
>
> kq = pool_get(&kqueue_pool, PR_WAITOK | PR_ZERO);
> - kq->kq_refs = 1;
> + refcnt_init(&kq->kq_refcnt);
> kq->kq_fdp = fdp;
> TAILQ_INIT(&kq->kq_head);
> mtx_init(&kq->kq_lock, IPL_HIGH);
> Index: sys/sys/eventvar.h
> ===================================================================
> RCS file: src/sys/sys/eventvar.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 eventvar.h
> --- sys/sys/eventvar.h 8 Feb 2022 08:56:41 -0000 1.13
> +++ sys/sys/eventvar.h 15 Mar 2022 13:43:20 -0000
> @@ -32,6 +32,7 @@
> #define _SYS_EVENTVAR_H_
>
> #include <sys/mutex.h>
> +#include <sys/refcnt.h>
> #include <sys/task.h>
>
> #define KQ_NEVENTS 8 /* minimize copy{in,out} calls */
> @@ -47,7 +48,7 @@ struct kqueue {
> struct mutex kq_lock; /* lock for queue access */
> TAILQ_HEAD(, knote) kq_head; /* [q] list of pending event */
> int kq_count; /* [q] # of pending events */
> - u_int kq_refs; /* [a] # of references */
> + struct refcnt kq_refcnt; /* [a] # of references */
> struct selinfo kq_sel;
> struct filedesc *kq_fdp; /* [I] fd table of this kq */
>