mirror of
https://github.com/fail0verflow/switch-linux.git
synced 2025-05-04 02:34:21 -04:00
ALSA: bebob: move mutex from function callee to callers
Currently, critical section is protected by mutex in functions of fireworks_stream.c. Callers increments/decrements substreams counter before calling the functions. Moving mutex to the callers code allows to change type of the substream counter from atomic_t to unsigned int. This commit is a preparation for obsoleting usage of atomic_t for substream counter. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
14a37ac1bf
commit
2a71e70166
3 changed files with 24 additions and 11 deletions
|
@ -17,8 +17,10 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_inc(&bebob->substreams_counter);
|
atomic_inc(&bebob->substreams_counter);
|
||||||
err = snd_bebob_stream_start_duplex(bebob, 0);
|
err = snd_bebob_stream_start_duplex(bebob, 0);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
snd_bebob_stream_lock_release(bebob);
|
snd_bebob_stream_lock_release(bebob);
|
||||||
end:
|
end:
|
||||||
|
@ -34,8 +36,10 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_inc(&bebob->substreams_counter);
|
atomic_inc(&bebob->substreams_counter);
|
||||||
err = snd_bebob_stream_start_duplex(bebob, 0);
|
err = snd_bebob_stream_start_duplex(bebob, 0);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
snd_bebob_stream_lock_release(bebob);
|
snd_bebob_stream_lock_release(bebob);
|
||||||
end:
|
end:
|
||||||
|
@ -46,8 +50,10 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_bebob *bebob = substream->rmidi->private_data;
|
struct snd_bebob *bebob = substream->rmidi->private_data;
|
||||||
|
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_dec(&bebob->substreams_counter);
|
atomic_dec(&bebob->substreams_counter);
|
||||||
snd_bebob_stream_stop_duplex(bebob);
|
snd_bebob_stream_stop_duplex(bebob);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
|
||||||
snd_bebob_stream_lock_release(bebob);
|
snd_bebob_stream_lock_release(bebob);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -57,8 +63,10 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_bebob *bebob = substream->rmidi->private_data;
|
struct snd_bebob *bebob = substream->rmidi->private_data;
|
||||||
|
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_dec(&bebob->substreams_counter);
|
atomic_dec(&bebob->substreams_counter);
|
||||||
snd_bebob_stream_stop_duplex(bebob);
|
snd_bebob_stream_stop_duplex(bebob);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
|
||||||
snd_bebob_stream_lock_release(bebob);
|
snd_bebob_stream_lock_release(bebob);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -218,8 +218,11 @@ pcm_capture_hw_params(struct snd_pcm_substream *substream,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
|
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_inc(&bebob->substreams_counter);
|
atomic_inc(&bebob->substreams_counter);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
amdtp_am824_set_pcm_format(&bebob->tx_stream, params_format(hw_params));
|
amdtp_am824_set_pcm_format(&bebob->tx_stream, params_format(hw_params));
|
||||||
|
|
||||||
|
@ -237,8 +240,11 @@ pcm_playback_hw_params(struct snd_pcm_substream *substream,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
|
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_inc(&bebob->substreams_counter);
|
atomic_inc(&bebob->substreams_counter);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
amdtp_am824_set_pcm_format(&bebob->rx_stream, params_format(hw_params));
|
amdtp_am824_set_pcm_format(&bebob->rx_stream, params_format(hw_params));
|
||||||
|
|
||||||
|
@ -250,8 +256,11 @@ pcm_capture_hw_free(struct snd_pcm_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_bebob *bebob = substream->private_data;
|
struct snd_bebob *bebob = substream->private_data;
|
||||||
|
|
||||||
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
|
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_dec(&bebob->substreams_counter);
|
atomic_dec(&bebob->substreams_counter);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
snd_bebob_stream_stop_duplex(bebob);
|
snd_bebob_stream_stop_duplex(bebob);
|
||||||
|
|
||||||
|
@ -262,8 +271,11 @@ pcm_playback_hw_free(struct snd_pcm_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_bebob *bebob = substream->private_data;
|
struct snd_bebob *bebob = substream->private_data;
|
||||||
|
|
||||||
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
|
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
|
||||||
|
mutex_lock(&bebob->mutex);
|
||||||
atomic_dec(&bebob->substreams_counter);
|
atomic_dec(&bebob->substreams_counter);
|
||||||
|
mutex_unlock(&bebob->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
snd_bebob_stream_stop_duplex(bebob);
|
snd_bebob_stream_stop_duplex(bebob);
|
||||||
|
|
||||||
|
|
|
@ -589,8 +589,6 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate)
|
||||||
unsigned int curr_rate;
|
unsigned int curr_rate;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
mutex_lock(&bebob->mutex);
|
|
||||||
|
|
||||||
/* Need no substreams */
|
/* Need no substreams */
|
||||||
if (atomic_read(&bebob->substreams_counter) == 0)
|
if (atomic_read(&bebob->substreams_counter) == 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -722,7 +720,6 @@ int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
mutex_unlock(&bebob->mutex);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -738,8 +735,6 @@ void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
|
||||||
master = &bebob->tx_stream;
|
master = &bebob->tx_stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&bebob->mutex);
|
|
||||||
|
|
||||||
if (atomic_read(&bebob->substreams_counter) == 0) {
|
if (atomic_read(&bebob->substreams_counter) == 0) {
|
||||||
amdtp_stream_pcm_abort(master);
|
amdtp_stream_pcm_abort(master);
|
||||||
amdtp_stream_stop(master);
|
amdtp_stream_stop(master);
|
||||||
|
@ -749,8 +744,6 @@ void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
|
||||||
|
|
||||||
break_both_connections(bebob);
|
break_both_connections(bebob);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&bebob->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)
|
void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)
|
||||||
|
|
Loading…
Add table
Reference in a new issue