Use sel{record,remove}_knote().

This commit is contained in:
thorpej 2020-12-19 01:18:58 +00:00
parent 7861a2d7ca
commit 2682e5ac8e
6 changed files with 47 additions and 53 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: apm.c,v 1.33 2017/10/28 04:53:54 riastradh Exp $ */
/* $NetBSD: apm.c,v 1.34 2020/12/19 01:18:58 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.33 2017/10/28 04:53:54 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.34 2020/12/19 01:18:58 thorpej Exp $");
#include "opt_apm.h"
@ -870,7 +870,7 @@ filt_apmrdetach(struct knote *kn)
struct apm_softc *sc = kn->kn_hook;
APM_LOCK(sc);
SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_rsel, kn);
APM_UNLOCK(sc);
}
@ -894,11 +894,9 @@ int
apmkqfilter(dev_t dev, struct knote *kn)
{
struct apm_softc *sc = device_lookup_private(&apm_cd, APMUNIT(dev));
struct klist *klist;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->sc_rsel.sel_klist;
kn->kn_fop = &apmread_filtops;
break;
@ -909,7 +907,7 @@ apmkqfilter(dev_t dev, struct knote *kn)
kn->kn_hook = sc;
APM_LOCK(sc);
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
selrecord_knote(&sc->sc_rsel, kn);
APM_UNLOCK(sc);
return (0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: audio.c,v 1.85 2020/12/13 05:47:08 isaki Exp $ */
/* $NetBSD: audio.c,v 1.86 2020/12/19 01:18:58 thorpej Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -138,7 +138,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.85 2020/12/13 05:47:08 isaki Exp $");
__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.86 2020/12/19 01:18:58 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@ -3143,7 +3143,7 @@ filt_audioread_detach(struct knote *kn)
TRACEF(3, file, "");
mutex_enter(sc->sc_lock);
SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_rsel, kn);
mutex_exit(sc->sc_lock);
}
@ -3190,7 +3190,7 @@ filt_audiowrite_detach(struct knote *kn)
TRACEF(3, file, "");
mutex_enter(sc->sc_lock);
SLIST_REMOVE(&sc->sc_wsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_wsel, kn);
mutex_exit(sc->sc_lock);
}
@ -3225,30 +3225,29 @@ filt_audiowrite_event(struct knote *kn, long hint)
int
audio_kqfilter(struct audio_softc *sc, audio_file_t *file, struct knote *kn)
{
struct klist *klist;
struct selinfo *sip;
TRACEF(3, file, "kn=%p kn_filter=%x", kn, (int)kn->kn_filter);
mutex_enter(sc->sc_lock);
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->sc_rsel.sel_klist;
sip = &sc->sc_rsel;
kn->kn_fop = &audioread_filtops;
break;
case EVFILT_WRITE:
klist = &sc->sc_wsel.sel_klist;
sip = &sc->sc_wsel;
kn->kn_fop = &audiowrite_filtops;
break;
default:
mutex_exit(sc->sc_lock);
return EINVAL;
}
kn->kn_hook = file;
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
mutex_enter(sc->sc_lock);
selrecord_knote(sip, kn);
mutex_exit(sc->sc_lock);
return 0;
@ -6078,7 +6077,6 @@ audio_softintr_rd(void *cookie)
/* Notify that data has arrived. */
selnotify(&sc->sc_rsel, 0, NOTE_SUBMIT);
KNOTE(&sc->sc_rsel.sel_klist, 0);
cv_broadcast(&sc->sc_rmixer->outcv);
mutex_exit(sc->sc_lock);
@ -6143,7 +6141,6 @@ audio_softintr_wr(void *cookie)
if (found) {
TRACE(4, "selnotify");
selnotify(&sc->sc_wsel, 0, NOTE_SUBMIT);
KNOTE(&sc->sc_wsel.sel_klist, 0);
}
/* Notify to audio_write() that outbuf available. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: apmdev.c,v 1.32 2018/07/21 18:11:09 maya Exp $ */
/* $NetBSD: apmdev.c,v 1.33 2020/12/19 01:18:59 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.32 2018/07/21 18:11:09 maya Exp $");
__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.33 2020/12/19 01:18:59 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_apm.h"
@ -911,7 +911,7 @@ filt_apmrdetach(struct knote *kn)
struct apm_softc *sc = kn->kn_hook;
APM_LOCK(sc);
SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_rsel, kn);
APM_UNLOCK(sc);
}
@ -935,11 +935,9 @@ int
apmdevkqfilter(dev_t dev, struct knote *kn)
{
struct apm_softc *sc = device_lookup_private(&apmdev_cd, APMUNIT(dev));
struct klist *klist;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->sc_rsel.sel_klist;
kn->kn_fop = &apmread_filtops;
break;
@ -950,7 +948,7 @@ apmdevkqfilter(dev_t dev, struct knote *kn)
kn->kn_hook = sc;
APM_LOCK(sc);
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
selrecord_knote(&sc->sc_rsel, kn);
APM_UNLOCK(sc);
return (0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: irframe_tty.c,v 1.63 2019/01/24 09:33:03 knakahara Exp $ */
/* $NetBSD: irframe_tty.c,v 1.64 2020/12/19 01:18:59 thorpej Exp $ */
/*
* TODO
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.63 2019/01/24 09:33:03 knakahara Exp $");
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.64 2020/12/19 01:18:59 thorpej Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -787,7 +787,7 @@ filt_irframetrdetach(struct knote *kn)
int s;
s = splir();
SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_rsel, kn);
splx(s);
}
@ -809,7 +809,7 @@ filt_irframetwdetach(struct knote *kn)
int s;
s = splir();
SLIST_REMOVE(&sc->sc_wsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->sc_wsel, kn);
splx(s);
}
@ -848,16 +848,16 @@ irframet_kqfilter(void *h, struct knote *kn)
{
struct tty *tp = h;
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
struct klist *klist;
struct selinfo *sip;
int s;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->sc_rsel.sel_klist;
sip = &sc->sc_rsel;
kn->kn_fop = &irframetread_filtops;
break;
case EVFILT_WRITE:
klist = &sc->sc_wsel.sel_klist;
sip = &sc->sc_wsel;
kn->kn_fop = &irframetwrite_filtops;
break;
default:
@ -867,7 +867,7 @@ irframet_kqfilter(void *h, struct knote *kn)
kn->kn_hook = tp;
s = splir();
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
selrecord_knote(sip, kn);
splx(s);
return (0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: midi.c,v 1.90 2020/05/23 23:42:42 ad Exp $ */
/* $NetBSD: midi.c,v 1.91 2020/12/19 01:18:58 thorpej Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.90 2020/05/23 23:42:42 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.91 2020/12/19 01:18:58 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "midi.h"
@ -1743,7 +1743,7 @@ filt_midirdetach(struct knote *kn)
struct midi_softc *sc = kn->kn_hook;
mutex_enter(sc->lock);
SLIST_REMOVE(&sc->rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->rsel, kn);
mutex_exit(sc->lock);
}
@ -1776,7 +1776,7 @@ filt_midiwdetach(struct knote *kn)
struct midi_softc *sc = kn->kn_hook;
mutex_enter(sc->lock);
SLIST_REMOVE(&sc->wsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->wsel, kn);
mutex_exit(sc->lock);
}
@ -1823,36 +1823,37 @@ midikqfilter(dev_t dev, struct knote *kn)
{
struct midi_softc *sc =
device_lookup_private(&midi_cd, MIDIUNIT(dev));
struct klist *klist;
struct selinfo *sip;
int error = 0;
mutex_exit(sc->lock);
sc->refcnt++;
mutex_enter(sc->lock);
sc->refcnt++;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->rsel.sel_klist;
sip = &sc->rsel;
kn->kn_fop = &midiread_filtops;
break;
case EVFILT_WRITE:
klist = &sc->wsel.sel_klist;
sip = &sc->wsel;
kn->kn_fop = &midiwrite_filtops;
break;
default:
return (EINVAL);
error = EINVAL;
goto out;
}
kn->kn_hook = sc;
mutex_enter(sc->lock);
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
selrecord_knote(sip, kn);
out:
if (--sc->refcnt < 0)
cv_broadcast(&sc->detach_cv);
mutex_exit(sc->lock);
return (0);
return (error);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: sequencer.c,v 1.72 2020/05/23 23:42:42 ad Exp $ */
/* $NetBSD: sequencer.c,v 1.73 2020/12/19 01:18:58 thorpej Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.72 2020/05/23 23:42:42 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.73 2020/12/19 01:18:58 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "sequencer.h"
@ -901,7 +901,7 @@ filt_sequencerrdetach(struct knote *kn)
struct sequencer_softc *sc = kn->kn_hook;
mutex_enter(&sc->lock);
SLIST_REMOVE(&sc->rsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->rsel, kn);
mutex_exit(&sc->lock);
}
@ -939,7 +939,7 @@ filt_sequencerwdetach(struct knote *kn)
struct sequencer_softc *sc = kn->kn_hook;
mutex_enter(&sc->lock);
SLIST_REMOVE(&sc->wsel.sel_klist, kn, knote, kn_selnext);
selremove_knote(&sc->wsel, kn);
mutex_exit(&sc->lock);
}
@ -975,18 +975,18 @@ static int
sequencerkqfilter(dev_t dev, struct knote *kn)
{
struct sequencer_softc *sc;
struct klist *klist;
struct selinfo *sip;
if ((sc = sequencerget(SEQUENCERUNIT(dev))) == NULL)
return ENXIO;
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &sc->rsel.sel_klist;
sip = &sc->rsel;
kn->kn_fop = &sequencerread_filtops;
break;
case EVFILT_WRITE:
klist = &sc->wsel.sel_klist;
sip = &sc->wsel;
kn->kn_fop = &sequencerwrite_filtops;
break;
@ -997,7 +997,7 @@ sequencerkqfilter(dev_t dev, struct knote *kn)
kn->kn_hook = sc;
mutex_enter(&sc->lock);
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
selrecord_knote(sip, kn);
mutex_exit(&sc->lock);
return (0);