summaryrefslogtreecommitdiff
path: root/src/ui_act.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-03-15 12:53:56 +0100
committerLars-Dominik Braun <lars@6xq.net>2018-03-15 12:53:56 +0100
commit3c4d8f65896253a82e19adcbe2808a863a99f74f (patch)
treefc7c3fbe15027e752c8a7da3d42c9a37d4d72c87 /src/ui_act.c
parent2e51a13fe816c0c0b02f7d7a19a4c739dcb66119 (diff)
downloadpianobar-3c4d8f65896253a82e19adcbe2808a863a99f74f.tar.gz
pianobar-3c4d8f65896253a82e19adcbe2808a863a99f74f.tar.bz2
pianobar-3c4d8f65896253a82e19adcbe2808a863a99f74f.zip
Properly protect player struct with mutex
The volatile keyword neither guarantees atomic access nor memory visibility[1]. Although this is usually not a problem on x86, it is incorrect to rely on this. Use mutex locks to protect all shared player variables and enforce memory visibility. [1] https://wiki.sei.cmu.edu/confluence/display/c/CON02-C.+Do+not+use+volatile+as+a+synchronization+primitive
Diffstat (limited to 'src/ui_act.c')
-rw-r--r--src/ui_act.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/ui_act.c b/src/ui_act.c
index 2c5f264..d112749 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2008-2013
+Copyright (c) 2008-2018
Lars-Dominik Braun <lars@6xq.net>
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -52,11 +52,11 @@ THE SOFTWARE.
static inline void BarUiDoSkipSong (player_t * const player) {
assert (player != NULL);
- pthread_mutex_lock (&player->pauseMutex);
+ pthread_mutex_lock (&player->lock);
player->doQuit = true;
player->doPause = false;
- pthread_cond_broadcast (&player->pauseCond);
- pthread_mutex_unlock (&player->pauseMutex);
+ pthread_cond_broadcast (&player->cond);
+ pthread_mutex_unlock (&player->lock);
}
/* transform station if necessary to allow changes like rename, rate, ...
@@ -419,28 +419,28 @@ BarUiActCallback(BarUiActSkipSong) {
/* play
*/
BarUiActCallback(BarUiActPlay) {
- pthread_mutex_lock (&app->player.pauseMutex);
+ pthread_mutex_lock (&app->player.lock);
app->player.doPause = false;
- pthread_cond_broadcast (&app->player.pauseCond);
- pthread_mutex_unlock (&app->player.pauseMutex);
+ pthread_cond_broadcast (&app->player.cond);
+ pthread_mutex_unlock (&app->player.lock);
}
/* pause
*/
BarUiActCallback(BarUiActPause) {
- pthread_mutex_lock (&app->player.pauseMutex);
+ pthread_mutex_lock (&app->player.lock);
app->player.doPause = true;
- pthread_cond_broadcast (&app->player.pauseCond);
- pthread_mutex_unlock (&app->player.pauseMutex);
+ pthread_cond_broadcast (&app->player.cond);
+ pthread_mutex_unlock (&app->player.lock);
}
/* toggle pause
*/
BarUiActCallback(BarUiActTogglePause) {
- pthread_mutex_lock (&app->player.pauseMutex);
+ pthread_mutex_lock (&app->player.lock);
app->player.doPause = !app->player.doPause;
- pthread_cond_broadcast (&app->player.pauseCond);
- pthread_mutex_unlock (&app->player.pauseMutex);
+ pthread_cond_broadcast (&app->player.cond);
+ pthread_mutex_unlock (&app->player.lock);
}
/* rename current station