Remove device list lock (dev_lck)

No longer necessary now that all device list operations happen in the
player thread.
This commit is contained in:
Julien BLACHE 2010-11-19 20:27:18 +01:00
parent 320d3b9dde
commit 25cdedc343

View File

@ -183,7 +183,6 @@ static uint64_t last_rtptime;
/* AirTunes devices */ /* AirTunes devices */
static time_t dev_deadline; static time_t dev_deadline;
static struct raop_device *dev_list; static struct raop_device *dev_list;
static pthread_mutex_t dev_lck = PTHREAD_MUTEX_INITIALIZER;
/* Device status */ /* Device status */
static enum laudio_state laudio_status; static enum laudio_state laudio_status;
@ -1158,7 +1157,7 @@ device_free(struct raop_device *dev)
free(dev); free(dev);
} }
/* Helpers - call with dev_lck held */ /* Helpers */
static void static void
device_remove(struct raop_device *dev) device_remove(struct raop_device *dev)
{ {
@ -1329,8 +1328,6 @@ device_streaming_cb(struct raop_device *dev, struct raop_session *rs, enum raop_
{ {
int ret; int ret;
pthread_mutex_lock(&dev_lck);
if (status == RAOP_FAILED) if (status == RAOP_FAILED)
{ {
raop_sessions--; raop_sessions--;
@ -1338,8 +1335,6 @@ device_streaming_cb(struct raop_device *dev, struct raop_session *rs, enum raop_
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during streaming!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during streaming!\n");
return; return;
@ -1362,8 +1357,6 @@ device_streaming_cb(struct raop_device *dev, struct raop_session *rs, enum raop_
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during streaming!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during streaming!\n");
return; return;
@ -1376,8 +1369,6 @@ device_streaming_cb(struct raop_device *dev, struct raop_session *rs, enum raop_
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
} }
pthread_mutex_unlock(&dev_lck);
} }
static void static void
@ -1411,13 +1402,9 @@ device_shutdown_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
if (raop_sessions) if (raop_sessions)
raop_sessions--; raop_sessions--;
pthread_mutex_lock(&dev_lck);
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared before shutdown completion!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared before shutdown completion!\n");
if (cur_cmd->ret != -2) if (cur_cmd->ret != -2)
@ -1430,8 +1417,6 @@ device_shutdown_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
pthread_mutex_unlock(&dev_lck);
out: out:
if (cur_cmd->raop_pending == 0) if (cur_cmd->raop_pending == 0)
{ {
@ -1461,13 +1446,9 @@ device_activate_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
cur_cmd->raop_pending--; cur_cmd->raop_pending--;
pthread_mutex_lock(&dev_lck);
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during startup!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during startup!\n");
raop_set_status_cb(rs, device_lost_cb); raop_set_status_cb(rs, device_lost_cb);
@ -1491,8 +1472,6 @@ device_activate_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
pthread_mutex_unlock(&dev_lck);
if (cur_cmd->ret != -2) if (cur_cmd->ret != -2)
cur_cmd->ret = -1; cur_cmd->ret = -1;
goto out; goto out;
@ -1500,8 +1479,6 @@ device_activate_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
dev->session = rs; dev->session = rs;
pthread_mutex_unlock(&dev_lck);
raop_sessions++; raop_sessions++;
if ((player_state == PLAY_PLAYING) && (raop_sessions == 1)) if ((player_state == PLAY_PLAYING) && (raop_sessions == 1))
@ -1546,13 +1523,9 @@ device_probe_cb(struct raop_device *dev, struct raop_session *rs, enum raop_sess
cur_cmd->raop_pending--; cur_cmd->raop_pending--;
pthread_mutex_lock(&dev_lck);
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during probe!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during probe!\n");
if (cur_cmd->ret != -2) if (cur_cmd->ret != -2)
@ -1573,15 +1546,11 @@ device_probe_cb(struct raop_device *dev, struct raop_session *rs, enum raop_sess
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
pthread_mutex_unlock(&dev_lck);
if (cur_cmd->ret != -2) if (cur_cmd->ret != -2)
cur_cmd->ret = -1; cur_cmd->ret = -1;
goto out; goto out;
} }
pthread_mutex_unlock(&dev_lck);
out: out:
if (cur_cmd->raop_pending == 0) if (cur_cmd->raop_pending == 0)
{ {
@ -1601,13 +1570,9 @@ device_restart_cb(struct raop_device *dev, struct raop_session *rs, enum raop_se
cur_cmd->raop_pending--; cur_cmd->raop_pending--;
pthread_mutex_lock(&dev_lck);
ret = device_check(dev); ret = device_check(dev);
if (ret < 0) if (ret < 0)
{ {
pthread_mutex_unlock(&dev_lck);
DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during restart!\n"); DPRINTF(E_WARN, L_PLAYER, "AirTunes device disappeared during restart!\n");
raop_set_status_cb(rs, device_lost_cb); raop_set_status_cb(rs, device_lost_cb);
@ -1623,15 +1588,11 @@ device_restart_cb(struct raop_device *dev, struct raop_session *rs, enum raop_se
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
pthread_mutex_unlock(&dev_lck);
goto out; goto out;
} }
dev->session = rs; dev->session = rs;
pthread_mutex_unlock(&dev_lck);
raop_sessions++; raop_sessions++;
raop_set_status_cb(rs, device_streaming_cb); raop_set_status_cb(rs, device_streaming_cb);
@ -1996,8 +1957,6 @@ playback_start(struct player_command *cmd)
/* Start RAOP sessions on selected devices if needed */ /* Start RAOP sessions on selected devices if needed */
cmd->raop_pending = 0; cmd->raop_pending = 0;
pthread_mutex_lock(&dev_lck);
for (rd = dev_list; rd; rd = rd->next) for (rd = dev_list; rd; rd = rd->next)
{ {
if (rd->selected && !rd->session) if (rd->selected && !rd->session)
@ -2013,8 +1972,6 @@ playback_start(struct player_command *cmd)
} }
} }
pthread_mutex_unlock(&dev_lck);
if ((laudio_status == LAUDIO_CLOSED) && (cmd->raop_pending == 0) && (raop_sessions == 0)) if ((laudio_status == LAUDIO_CLOSED) && (cmd->raop_pending == 0) && (raop_sessions == 0))
{ {
DPRINTF(E_LOG, L_PLAYER, "Could not start playback: no output selected or couldn't start any output\n"); DPRINTF(E_LOG, L_PLAYER, "Could not start playback: no output selected or couldn't start any output\n");
@ -2238,8 +2195,6 @@ speaker_enumerate(struct player_command *cmd)
laudio_name = cfg_getstr(cfg_getsec(cfg, "audio"), "nickname"); laudio_name = cfg_getstr(cfg_getsec(cfg, "audio"), "nickname");
pthread_mutex_lock(&dev_lck);
/* Auto-select local audio if there are no AirTunes devices */ /* Auto-select local audio if there are no AirTunes devices */
if (!dev_list) if (!dev_list)
laudio_selected = 1; laudio_selected = 1;
@ -2252,8 +2207,6 @@ speaker_enumerate(struct player_command *cmd)
spk_enum->cb(rd->id, rd->name, rd->selected, rd->has_password, spk_enum->arg); spk_enum->cb(rd->id, rd->name, rd->selected, rd->has_password, spk_enum->arg);
} }
pthread_mutex_unlock(&dev_lck);
return 0; return 0;
} }
@ -2392,8 +2345,6 @@ speaker_set(struct player_command *cmd)
cmd->raop_pending = 0; cmd->raop_pending = 0;
cmd->ret = 0; cmd->ret = 0;
pthread_mutex_lock(&dev_lck);
/* RAOP devices */ /* RAOP devices */
for (rd = dev_list; rd; rd = rd->next) for (rd = dev_list; rd; rd = rd->next)
{ {
@ -2457,8 +2408,6 @@ speaker_set(struct player_command *cmd)
} }
} }
pthread_mutex_unlock(&dev_lck);
/* Local audio */ /* Local audio */
for (i = 1; i <= nspk; i++) for (i = 1; i <= nspk; i++)
{ {
@ -3354,13 +3303,11 @@ player(void *arg)
if (laudio_selected) if (laudio_selected)
db_config_save_hex64(VAR_ACTIVE_SPK, 0); db_config_save_hex64(VAR_ACTIVE_SPK, 0);
pthread_mutex_lock(&dev_lck);
for (rd = dev_list; rd; rd = rd->next) for (rd = dev_list; rd; rd = rd->next)
{ {
if (rd->selected) if (rd->selected)
db_config_save_hex64(VAR_ACTIVE_SPK, rd->id); db_config_save_hex64(VAR_ACTIVE_SPK, rd->id);
} }
pthread_mutex_unlock(&dev_lck);
db_perthread_deinit(); db_perthread_deinit();