aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/kern_event.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index a735dfaa97df..69fdfa121c50 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -700,7 +700,8 @@ struct kq_timer_cb_data {
sbintime_t to; /* precalculated timer period, 0 for abs */
};
-#define KQ_TIMER_CB_ENQUEUED 0x01
+#define KQ_TIMER_CB_ENQUEUED 0x01 /* in queue of stopped timers */
+#define KQ_TIMER_CB_DETACHING 0x02 /* detach started, don't requeue */
static void
kqtimer_sched_callout(struct kq_timer_cb_data *kc)
@@ -768,7 +769,8 @@ filt_timerexpire_l(struct knote *kn, bool proc_locked)
if (!proc_locked)
PROC_LOCK(p);
if (P_SHOULDSTOP(p) || P_KILLED(p)) {
- if ((kc->flags & KQ_TIMER_CB_ENQUEUED) == 0) {
+ if ((kc->flags & (KQ_TIMER_CB_ENQUEUED |
+ KQ_TIMER_CB_DETACHING)) == 0) {
/*
* Insert into head so that
* kqtimer_proc_continue() does not
@@ -881,24 +883,16 @@ filt_timerdetach(struct knote *kn)
{
struct kq_timer_cb_data *kc;
unsigned int old __unused;
- bool pending;
kc = kn->kn_ptr.p_v;
- do {
- callout_drain(&kc->c);
-
- /*
- * kqtimer_proc_continue() might have rescheduled this callout.
- * Double-check, using the process mutex as an interlock.
- */
- PROC_LOCK(kc->p);
- if ((kc->flags & KQ_TIMER_CB_ENQUEUED) != 0) {
- kc->flags &= ~KQ_TIMER_CB_ENQUEUED;
- TAILQ_REMOVE(&kc->p->p_kqtim_stop, kc, link);
- }
- pending = callout_pending(&kc->c);
- PROC_UNLOCK(kc->p);
- } while (pending);
+ PROC_LOCK(kc->p);
+ kc->flags |= KQ_TIMER_CB_DETACHING;
+ if ((kc->flags & KQ_TIMER_CB_ENQUEUED) != 0) {
+ kc->flags &= ~KQ_TIMER_CB_ENQUEUED;
+ TAILQ_REMOVE(&kc->p->p_kqtim_stop, kc, link);
+ }
+ PROC_UNLOCK(kc->p);
+ callout_drain(&kc->c);
free(kc, M_KQUEUE);
old = atomic_fetchadd_int(&kq_ncallouts, -1);
KASSERT(old > 0, ("Number of callouts cannot become negative"));