Skip to content

Commit

Permalink
ALSA: fireworks: change type of substream counter from atomic_t to un…
Browse files Browse the repository at this point in the history
…signed int

The counter is incremented/decremented in critical section protected with
mutex. Therefore, no need to use atomic_t.

This commit changes the type to unsigned int.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Sakamoto authored and Takashi Iwai committed Nov 14, 2015
1 parent ea54a37 commit 4d2c50a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions sound/firewire/fireworks/fireworks.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ struct snd_efw {
struct amdtp_stream rx_stream;
struct cmp_connection out_conn;
struct cmp_connection in_conn;
atomic_t capture_substreams;
atomic_t playback_substreams;
unsigned int capture_substreams;
unsigned int playback_substreams;

/* hardware metering parameters */
unsigned int phys_out;
Expand Down
8 changes: 4 additions & 4 deletions sound/firewire/fireworks/fireworks_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
goto end;

mutex_lock(&efw->mutex);
atomic_inc(&efw->capture_substreams);
efw->capture_substreams++;
err = snd_efw_stream_start_duplex(efw, 0);
mutex_unlock(&efw->mutex);
if (err < 0)
Expand All @@ -38,7 +38,7 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
goto end;

mutex_lock(&efw->mutex);
atomic_inc(&efw->playback_substreams);
efw->playback_substreams++;
err = snd_efw_stream_start_duplex(efw, 0);
mutex_unlock(&efw->mutex);
if (err < 0)
Expand All @@ -52,7 +52,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
struct snd_efw *efw = substream->rmidi->private_data;

mutex_lock(&efw->mutex);
atomic_dec(&efw->capture_substreams);
efw->capture_substreams--;
snd_efw_stream_stop_duplex(efw);
mutex_unlock(&efw->mutex);

Expand All @@ -65,7 +65,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
struct snd_efw *efw = substream->rmidi->private_data;

mutex_lock(&efw->mutex);
atomic_dec(&efw->playback_substreams);
efw->playback_substreams--;
snd_efw_stream_stop_duplex(efw);
mutex_unlock(&efw->mutex);

Expand Down
8 changes: 4 additions & 4 deletions sound/firewire/fireworks/fireworks_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream,

if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex);
atomic_inc(&efw->capture_substreams);
efw->capture_substreams++;
mutex_unlock(&efw->mutex);
}

Expand All @@ -274,7 +274,7 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream,

if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex);
atomic_inc(&efw->playback_substreams);
efw->playback_substreams++;
mutex_unlock(&efw->mutex);
}

Expand All @@ -289,7 +289,7 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)

if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex);
atomic_dec(&efw->capture_substreams);
efw->capture_substreams--;
mutex_unlock(&efw->mutex);
}

Expand All @@ -303,7 +303,7 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream)

if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
mutex_lock(&efw->mutex);
atomic_dec(&efw->playback_substreams);
efw->playback_substreams--;
mutex_unlock(&efw->mutex);
}

Expand Down
25 changes: 12 additions & 13 deletions sound/firewire/fireworks/fireworks_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,13 @@ int snd_efw_stream_init_duplex(struct snd_efw *efw)
int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
{
struct amdtp_stream *master, *slave;
atomic_t *slave_substreams;
unsigned int slave_substreams;
enum cip_flags sync_mode;
unsigned int curr_rate;
int err = 0;

/* Need no substreams */
if ((atomic_read(&efw->playback_substreams) == 0) &&
(atomic_read(&efw->capture_substreams) == 0))
if (efw->playback_substreams == 0 && efw->capture_substreams == 0)
goto end;

err = get_sync_mode(efw, &sync_mode);
Expand All @@ -225,11 +224,11 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
if (sync_mode == CIP_SYNC_TO_DEVICE) {
master = &efw->tx_stream;
slave = &efw->rx_stream;
slave_substreams = &efw->playback_substreams;
slave_substreams = efw->playback_substreams;
} else {
master = &efw->rx_stream;
slave = &efw->tx_stream;
slave_substreams = &efw->capture_substreams;
slave_substreams = efw->capture_substreams;
}

/*
Expand Down Expand Up @@ -275,7 +274,7 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
}

/* start slave if needed */
if (atomic_read(slave_substreams) > 0 && !amdtp_stream_running(slave)) {
if (slave_substreams > 0 && !amdtp_stream_running(slave)) {
err = start_stream(efw, slave, rate);
if (err < 0) {
dev_err(&efw->unit->device,
Expand All @@ -290,24 +289,24 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
void snd_efw_stream_stop_duplex(struct snd_efw *efw)
{
struct amdtp_stream *master, *slave;
atomic_t *master_substreams, *slave_substreams;
unsigned int master_substreams, slave_substreams;

if (efw->master == &efw->rx_stream) {
slave = &efw->tx_stream;
master = &efw->rx_stream;
slave_substreams = &efw->capture_substreams;
master_substreams = &efw->playback_substreams;
slave_substreams = efw->capture_substreams;
master_substreams = efw->playback_substreams;
} else {
slave = &efw->rx_stream;
master = &efw->tx_stream;
slave_substreams = &efw->playback_substreams;
master_substreams = &efw->capture_substreams;
slave_substreams = efw->playback_substreams;
master_substreams = efw->capture_substreams;
}

if (atomic_read(slave_substreams) == 0) {
if (slave_substreams == 0) {
stop_stream(efw, slave);

if (atomic_read(master_substreams) == 0)
if (master_substreams == 0)
stop_stream(efw, master);
}
}
Expand Down

0 comments on commit 4d2c50a

Please sign in to comment.