Commit 05c1afe7 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] opl3 - simplify exclusive access lock

Use the exclusive access lock in hwdep instead of the own one.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 224a0332
...@@ -320,7 +320,6 @@ struct snd_opl3 { ...@@ -320,7 +320,6 @@ struct snd_opl3 {
spinlock_t reg_lock; spinlock_t reg_lock;
struct snd_card *card; /* The card that this belongs to */ struct snd_card *card; /* The card that this belongs to */
int used; /* usage flag - exclusive */
unsigned char fm_mode; /* OPL mode, see SNDRV_DM_FM_MODE_XXX */ unsigned char fm_mode; /* OPL mode, see SNDRV_DM_FM_MODE_XXX */
unsigned char rhythm; /* percussion mode flag */ unsigned char rhythm; /* percussion mode flag */
unsigned char max_voices; /* max number of voices */ unsigned char max_voices; /* max number of voices */
...@@ -353,7 +352,6 @@ struct snd_opl3 { ...@@ -353,7 +352,6 @@ struct snd_opl3 {
int sys_timer_status; /* system timer run status */ int sys_timer_status; /* system timer run status */
spinlock_t sys_timer_lock; /* Lock for system timer access */ spinlock_t sys_timer_lock; /* Lock for system timer access */
#endif #endif
struct mutex access_mutex; /* locking */
}; };
/* opl3.c */ /* opl3.c */
......
...@@ -361,7 +361,6 @@ int snd_opl3_new(struct snd_card *card, ...@@ -361,7 +361,6 @@ int snd_opl3_new(struct snd_card *card,
opl3->hardware = hardware; opl3->hardware = hardware;
spin_lock_init(&opl3->reg_lock); spin_lock_init(&opl3->reg_lock);
spin_lock_init(&opl3->timer_lock); spin_lock_init(&opl3->timer_lock);
mutex_init(&opl3->access_mutex);
if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) { if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) {
snd_opl3_free(opl3); snd_opl3_free(opl3);
...@@ -497,6 +496,7 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3, ...@@ -497,6 +496,7 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3,
return err; return err;
} }
hw->private_data = opl3; hw->private_data = opl3;
hw->exclusive = 1;
#ifdef CONFIG_SND_OSSEMUL #ifdef CONFIG_SND_OSSEMUL
if (device == 0) { if (device == 0) {
hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM; hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM;
......
...@@ -51,14 +51,15 @@ void snd_opl3_synth_use_dec(struct snd_opl3 * opl3) ...@@ -51,14 +51,15 @@ void snd_opl3_synth_use_dec(struct snd_opl3 * opl3)
int snd_opl3_synth_setup(struct snd_opl3 * opl3) int snd_opl3_synth_setup(struct snd_opl3 * opl3)
{ {
int idx; int idx;
struct snd_hwdep *hwdep = opl3->hwdep;
mutex_lock(&opl3->access_mutex); mutex_lock(&hwdep->open_mutex);
if (opl3->used) { if (hwdep->used) {
mutex_unlock(&opl3->access_mutex); mutex_unlock(&hwdep->open_mutex);
return -EBUSY; return -EBUSY;
} }
opl3->used++; hwdep->used++;
mutex_unlock(&opl3->access_mutex); mutex_unlock(&hwdep->open_mutex);
snd_opl3_reset(opl3); snd_opl3_reset(opl3);
...@@ -91,9 +92,11 @@ void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) ...@@ -91,9 +92,11 @@ void snd_opl3_synth_cleanup(struct snd_opl3 * opl3)
spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); spin_unlock_irqrestore(&opl3->sys_timer_lock, flags);
snd_opl3_reset(opl3); snd_opl3_reset(opl3);
mutex_lock(&opl3->access_mutex); hwdep = opl3->hwdep;
opl3->used--; mutex_lock(&hwdep->open_mutex);
mutex_unlock(&opl3->access_mutex); hwdep->used--;
mutex_unlock(&hwdep->open_mutex);
wake_up(&hwdep->open_wait);
} }
static int snd_opl3_synth_use(void *private_data, struct snd_seq_port_subscribe * info) static int snd_opl3_synth_use(void *private_data, struct snd_seq_port_subscribe * info)
......
...@@ -76,16 +76,6 @@ static int snd_opl3_set_connection(struct snd_opl3 * opl3, int connection); ...@@ -76,16 +76,6 @@ static int snd_opl3_set_connection(struct snd_opl3 * opl3, int connection);
*/ */
int snd_opl3_open(struct snd_hwdep * hw, struct file *file) int snd_opl3_open(struct snd_hwdep * hw, struct file *file)
{ {
struct snd_opl3 *opl3 = hw->private_data;
mutex_lock(&opl3->access_mutex);
if (opl3->used) {
mutex_unlock(&opl3->access_mutex);
return -EAGAIN;
}
opl3->used++;
mutex_unlock(&opl3->access_mutex);
return 0; return 0;
} }
...@@ -185,10 +175,6 @@ int snd_opl3_release(struct snd_hwdep * hw, struct file *file) ...@@ -185,10 +175,6 @@ int snd_opl3_release(struct snd_hwdep * hw, struct file *file)
struct snd_opl3 *opl3 = hw->private_data; struct snd_opl3 *opl3 = hw->private_data;
snd_opl3_reset(opl3); snd_opl3_reset(opl3);
mutex_lock(&opl3->access_mutex);
opl3->used--;
mutex_unlock(&opl3->access_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment