Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145216315
D53029.1777526834.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D53029.1777526834.diff
View Options
diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -313,6 +313,7 @@
bs = c->bufsoft;
if (CHN_EMPTY(c, children.busy)) {
+ KNOTE_LOCKED(&bs->sel.si_note, 0);
if (SEL_WAITING(sndbuf_getsel(bs)) && chn_polltrigger(c))
selwakeuppri(sndbuf_getsel(bs), PRIBIO);
CHN_BROADCAST(&c->intr_cv);
diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -81,6 +81,7 @@
static d_poll_t dsp_poll;
static d_mmap_t dsp_mmap;
static d_mmap_single_t dsp_mmap_single;
+static d_kqfilter_t dsp_kqfilter;
struct cdevsw dsp_cdevsw = {
.d_version = D_VERSION,
@@ -89,6 +90,7 @@
.d_write = dsp_write,
.d_ioctl = dsp_ioctl,
.d_poll = dsp_poll,
+ .d_kqfilter = dsp_kqfilter,
.d_mmap = dsp_mmap,
.d_mmap_single = dsp_mmap_single,
.d_name = "dsp",
@@ -235,6 +237,7 @@
chn_vpc_reset(*ch, SND_VOL_C_PCM, 0);
CHN_UNLOCK(*ch);
+ knlist_init_mtx(&(*ch)->bufsoft->sel.si_note, (*ch)->lock);
return (0);
}
@@ -264,10 +267,16 @@
rdch = priv->rdch;
wrch = priv->wrch;
- if (rdch != NULL)
+ if (rdch != NULL) {
+ knlist_clear(&rdch->bufsoft->sel.si_note, 0);
+ knlist_destroy(&rdch->bufsoft->sel.si_note);
CHN_REMOVE(d, rdch, channels.pcm.opened);
- if (wrch != NULL)
+ }
+ if (wrch != NULL) {
+ knlist_clear(&wrch->bufsoft->sel.si_note, 0);
+ knlist_destroy(&wrch->bufsoft->sel.si_note);
CHN_REMOVE(d, wrch, channels.pcm.opened);
+ }
if (rdch != NULL || wrch != NULL) {
PCM_UNLOCK(d);
@@ -2962,6 +2971,139 @@
return (ret);
}
+static void
+dsp_kqdetach(struct knote *kn)
+{
+ struct dsp_cdevpriv *priv = kn->kn_hook;
+ struct snddev_info *d;
+ struct pcm_channel *ch;
+
+ d = priv->sc;
+ if (!DSP_REGISTERED(d))
+ return;
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ ch = priv->rdch;
+ break;
+ case EVFILT_WRITE:
+ ch = priv->wrch;
+ break;
+ default:
+ return;
+ }
+ if (ch != NULL) {
+ CHN_LOCK(ch);
+ knlist_remove(&ch->bufsoft->sel.si_note, kn, 1);
+ CHN_UNLOCK(ch);
+ }
+}
+
+static int
+dsp_read_filter(struct knote *kn, long hint)
+{
+ struct dsp_cdevpriv *priv = kn->kn_hook;
+ struct snddev_info *d;
+ struct pcm_channel *ch;
+
+ d = priv->sc;
+ if (!DSP_REGISTERED(d)) {
+ kn->kn_data = EBADF;
+ kn->kn_flags |= EV_ERROR;
+ return (1);
+ }
+ ch = priv->rdch;
+ CHN_LOCKOWNED(ch);
+ if (ch != NULL && !(ch->flags & CHN_F_DEAD))
+ kn->kn_data = sndbuf_getready(ch->bufsoft);
+ else
+ kn->kn_data = 0;
+
+ return (kn->kn_data > 0);
+}
+
+static int
+dsp_write_filter(struct knote *kn, long hint)
+{
+ struct dsp_cdevpriv *priv = kn->kn_hook;
+ struct snddev_info *d;
+ struct pcm_channel *ch;
+
+ d = priv->sc;
+ if (!DSP_REGISTERED(d)) {
+ kn->kn_data = EBADF;
+ kn->kn_flags |= EV_ERROR;
+ return (1);
+ }
+ ch = priv->wrch;
+ CHN_LOCKOWNED(ch);
+ if (ch != NULL && !(ch->flags & CHN_F_DEAD))
+ kn->kn_data = sndbuf_getfree(ch->bufsoft);
+ else
+ kn->kn_data = 0;
+
+ return (kn->kn_data > 0);
+}
+
+static const struct filterops dsp_read_filtops = {
+ .f_isfd = 1,
+ .f_detach = dsp_kqdetach,
+ .f_event = dsp_read_filter,
+};
+
+static const struct filterops dsp_write_filtops = {
+ .f_isfd = 1,
+ .f_detach = dsp_kqdetach,
+ .f_event = dsp_write_filter,
+};
+
+static int
+dsp_kqfilter(struct cdev *dev, struct knote *kn)
+{
+ struct dsp_cdevpriv *priv;
+ struct snddev_info *d;
+ int err = 0;
+
+ if ((err = devfs_get_cdevpriv((void **)&priv)) != 0)
+ return (err);
+
+ d = priv->sc;
+ if (!DSP_REGISTERED(d))
+ return (EBADF);
+ PCM_GIANT_ENTER(d);
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ if (priv->rdch == NULL) {
+ err = EINVAL;
+ break;
+ }
+ kn->kn_fop = &dsp_read_filtops;
+ CHN_LOCK(priv->rdch);
+ knlist_add(&priv->rdch->bufsoft->sel.si_note, kn, 1);
+ CHN_UNLOCK(priv->rdch);
+ break;
+ case EVFILT_WRITE:
+ if (priv->wrch == NULL) {
+ err = EINVAL;
+ break;
+ }
+ kn->kn_fop = &dsp_write_filtops;
+ CHN_LOCK(priv->wrch);
+ knlist_add(&priv->wrch->bufsoft->sel.si_note, kn, 1);
+ CHN_UNLOCK(priv->wrch);
+ break;
+ default:
+ kn->kn_hook = NULL;
+ err = EINVAL;
+ break;
+ }
+ PCM_GIANT_LEAVE(d);
+ if (err == 0)
+ kn->kn_hook = priv;
+
+ return (err);
+}
+
+
#ifdef OSSV4_EXPERIMENT
/**
* @brief Retrieve an audio device's label
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 30, 5:27 AM (10 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28490598
Default Alt Text
D53029.1777526834.diff (4 KB)
Attached To
Mode
D53029: sound: Add kqueue support
Attached
Detach File
Event Timeline
Log In to Comment