-/* $OpenBSD: kern_event.c,v 1.190 2022/06/20 01:39:44 visa Exp $ */
+/* $OpenBSD: kern_event.c,v 1.191 2022/06/27 13:35:21 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
kqueue_terminate(struct proc *p, struct kqueue *kq)
{
struct knote *kn;
+ int state;
mtx_enter(&kq->kq_lock);
KASSERT(kn->kn_filter == EVFILT_MARKER);
kq->kq_state |= KQ_DYING;
+ state = kq->kq_state;
kqueue_wakeup(kq);
mtx_leave(&kq->kq_lock);
+ /*
+ * Any knotes that were attached to this kqueue were deleted
+ * by knote_fdclose() when this kqueue's file descriptor was closed.
+ */
KASSERT(klist_empty(&kq->kq_sel.si_note));
- task_del(systqmp, &kq->kq_task);
+ if (state & KQ_TASK)
+ taskq_del_barrier(systqmp, &kq->kq_task);
}
int
mtx_enter(&kqueue_klist_lock);
KNOTE(&kq->kq_sel.si_note, 0);
mtx_leave(&kqueue_klist_lock);
- KQRELE(kq);
}
void
}
if (!klist_empty(&kq->kq_sel.si_note)) {
/* Defer activation to avoid recursion. */
- KQREF(kq);
- if (!task_add(systqmp, &kq->kq_task))
- KQRELE(kq);
+ kq->kq_state |= KQ_TASK;
+ task_add(systqmp, &kq->kq_task);
}
}
-/* $OpenBSD: eventvar.h,v 1.15 2022/06/20 01:39:44 visa Exp $ */
+/* $OpenBSD: eventvar.h,v 1.16 2022/06/27 13:35:21 visa Exp $ */
/*-
* Copyright (c) 1999,2000 Jonathan Lemon <jlemon@FreeBSD.org>
int kq_state; /* [q] */
#define KQ_SLEEP 0x02
#define KQ_DYING 0x04
+#define KQ_TASK 0x08
};
#endif /* !_SYS_EVENTVAR_H_ */