diff options
author | Takashi Iwai <tiwai@suse.de> | 2014-11-07 11:08:28 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-11-09 12:20:40 -0500 |
commit | 1fb8510cdb5b7befe8a59f533c7fc12ef0dac73e (patch) | |
tree | b44569425ea7683d02893cfd145081a11d7677f1 /sound/core/pcm_native.c | |
parent | 31584ed18c073176a7ad96ddbfd09765e21e813d (diff) |
ALSA: pcm: Add snd_pcm_stop_xrun() helper
Add a new helper function snd_pcm_stop_xrun() to the standard sequnce
lock/snd_pcm_stop(XRUN)/unlock by a single call, and replace the
existing open codes with this helper.
The function checks the PCM running state to prevent setting the wrong
state, too, for more safety.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/pcm_native.c')
-rw-r--r-- | sound/core/pcm_native.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index dfb5031969f8..a3d122109704 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
@@ -1098,6 +1098,29 @@ int snd_pcm_drain_done(struct snd_pcm_substream *substream) | |||
1098 | SNDRV_PCM_STATE_SETUP); | 1098 | SNDRV_PCM_STATE_SETUP); |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | /** | ||
1102 | * snd_pcm_stop_xrun - stop the running streams as XRUN | ||
1103 | * @substream: the PCM substream instance | ||
1104 | * @state: PCM state after stopping the stream | ||
1105 | * | ||
1106 | * This stops the given running substream (and all linked substreams) as XRUN. | ||
1107 | * Unlike snd_pcm_stop(), this function takes the substream lock by itself. | ||
1108 | * | ||
1109 | * Return: Zero if successful, or a negative error code. | ||
1110 | */ | ||
1111 | int snd_pcm_stop_xrun(struct snd_pcm_substream *substream) | ||
1112 | { | ||
1113 | unsigned long flags; | ||
1114 | int ret = 0; | ||
1115 | |||
1116 | snd_pcm_stream_lock_irqsave(substream, flags); | ||
1117 | if (snd_pcm_running(substream)) | ||
1118 | ret = snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
1119 | snd_pcm_stream_unlock_irqrestore(substream, flags); | ||
1120 | return ret; | ||
1121 | } | ||
1122 | EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun); | ||
1123 | |||
1101 | /* | 1124 | /* |
1102 | * pause callbacks | 1125 | * pause callbacks |
1103 | */ | 1126 | */ |