Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153185612
D49805.id153588.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D49805.id153588.diff
View Options
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
@@ -91,6 +91,7 @@
static eventhandler_tag dsp_ehtag = NULL;
+static void dsp_close_chan(struct pcm_channel *c);
static int dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group);
static int dsp_oss_syncstart(int sg_id);
static int dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy);
@@ -241,20 +242,19 @@
#define DSP_F_WRITE(x) ((x) & FWRITE)
static void
-dsp_close(void *data)
+dsp_close_chan(struct pcm_channel *c)
{
- struct dsp_cdevpriv *priv = data;
- struct pcm_channel *rdch, *wrch, *parent;
struct snddev_info *d;
+ struct pcm_channel *parent;
int sg_ids;
- if (priv == NULL)
+ if (c == NULL)
return;
- d = priv->sc;
+ d = c->parentsnddev;
/* At this point pcm_unregister() will destroy all channels anyway. */
if (!DSP_REGISTERED(d))
- goto skip;
+ return;
PCM_GIANT_ENTER(d);
@@ -262,82 +262,63 @@
PCM_WAIT(d);
PCM_ACQUIRE(d);
- rdch = priv->rdch;
- wrch = priv->wrch;
+ CHN_REMOVE(d, c, channels.pcm.opened);
- if (rdch != NULL)
- CHN_REMOVE(d, rdch, channels.pcm.opened);
- if (wrch != NULL)
- CHN_REMOVE(d, wrch, channels.pcm.opened);
+ PCM_UNLOCK(d);
- if (rdch != NULL || wrch != NULL) {
- PCM_UNLOCK(d);
- if (rdch != NULL) {
- /*
- * The channel itself need not be locked because:
- * a) Adding a channel to a syncgroup happens only
- * in dsp_ioctl(), which cannot run concurrently
- * to dsp_close().
- * b) The syncmember pointer (sm) is protected by
- * the global syncgroup list lock.
- * c) A channel can't just disappear, invalidating
- * pointers, unless it's closed/dereferenced
- * first.
- */
- PCM_SG_LOCK();
- sg_ids = chn_syncdestroy(rdch);
- PCM_SG_UNLOCK();
- if (sg_ids != 0)
- free_unr(pcmsg_unrhdr, sg_ids);
-
- if (rdch->flags & CHN_F_VIRTUAL) {
- parent = rdch->parentchannel;
- CHN_LOCK(parent);
- CHN_LOCK(rdch);
- vchan_destroy(rdch);
- CHN_UNLOCK(parent);
- } else {
- CHN_LOCK(rdch);
- chn_abort(rdch); /* won't sleep */
- rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP |
- CHN_F_DEAD | CHN_F_EXCLUSIVE);
- chn_reset(rdch, 0, 0);
- chn_release(rdch);
- }
- }
- if (wrch != NULL) {
- /*
- * Please see block above.
- */
- PCM_SG_LOCK();
- sg_ids = chn_syncdestroy(wrch);
- PCM_SG_UNLOCK();
- if (sg_ids != 0)
- free_unr(pcmsg_unrhdr, sg_ids);
-
- if (wrch->flags & CHN_F_VIRTUAL) {
- parent = wrch->parentchannel;
- CHN_LOCK(parent);
- CHN_LOCK(wrch);
- vchan_destroy(wrch);
- CHN_UNLOCK(parent);
- } else {
- CHN_LOCK(wrch);
- chn_flush(wrch); /* may sleep */
- wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP |
- CHN_F_DEAD | CHN_F_EXCLUSIVE);
- chn_reset(wrch, 0, 0);
- chn_release(wrch);
- }
- }
- PCM_LOCK(d);
+ /*
+ * The channel itself need not be locked because:
+ * a) Adding a channel to a syncgroup happens only in dsp_ioctl(),
+ * which cannot run concurrently to dsp_close_chan().
+ * b) The syncmember pointer (sm) is protected by the global
+ * syncgroup list lock.
+ * c) A channel can't just disappear, invalidating pointers, unless
+ * it's closed/dereferenced first.
+ */
+ PCM_SG_LOCK();
+ sg_ids = chn_syncdestroy(c);
+ PCM_SG_UNLOCK();
+ if (sg_ids != 0)
+ free_unr(pcmsg_unrhdr, sg_ids);
+
+ if (c->flags & CHN_F_VIRTUAL) {
+ parent = c->parentchannel;
+ CHN_LOCK(parent);
+ CHN_LOCK(c);
+ vchan_destroy(c);
+ CHN_UNLOCK(parent);
+ } else {
+ CHN_LOCK(c);
+ if (c->direction == PCMDIR_REC)
+ chn_abort(c); /* won't sleep */
+ else
+ chn_flush(c); /* may sleep */
+ c->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP | CHN_F_DEAD |
+ CHN_F_EXCLUSIVE);
+ chn_reset(c, 0, 0);
+ chn_release(c);
}
+ PCM_LOCK(d);
+
PCM_RELEASE(d);
PCM_UNLOCK(d);
PCM_GIANT_LEAVE(d);
-skip:
+}
+
+
+static void
+dsp_close(void *data)
+{
+ struct dsp_cdevpriv *priv = data;
+
+ if (priv == NULL)
+ return;
+
+ dsp_close_chan(priv->rdch);
+ dsp_close_chan(priv->wrch);
+
free(priv, M_DEVBUF);
priv = NULL;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 20, 4:30 PM (14 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31850800
Default Alt Text
D49805.id153588.diff (4 KB)
Attached To
Mode
D49805: sound: Create a dsp_close() helper function
Attached
Detach File
Event Timeline
Log In to Comment