summaryrefslogtreecommitdiff
path: root/src/ui_act.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2012-04-20 11:49:02 +0200
committerLars-Dominik Braun <lars@6xq.net>2012-05-14 12:07:52 +0200
commit7df9371491e96a99c1e463f7787aede352ac5a37 (patch)
tree543ac60162bae17c03a3adb21c0db3d8ac5317b8 /src/ui_act.c
parentc4330c3f65b2eacd3433ba19b1483f6704303205 (diff)
downloadpianobar-windows-7df9371491e96a99c1e463f7787aede352ac5a37.tar.gz
pianobar-windows-7df9371491e96a99c1e463f7787aede352ac5a37.tar.bz2
pianobar-windows-7df9371491e96a99c1e463f7787aede352ac5a37.zip
Remove pause mutex/add pthread cleanup function
No more mutex locking/checking for quit condition. Should (slightly) increase responsiveness of the player thread. Closes #250.
Diffstat (limited to 'src/ui_act.c')
-rw-r--r--src/ui_act.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/ui_act.c b/src/ui_act.c
index 0c9ed1b..2cc3197 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -23,10 +23,14 @@ THE SOFTWARE.
/* functions responding to user's keystrokes */
+#ifndef __FreeBSD__
+#define _POSIX_C_SOURCE 200112L /* pthread_kill() */
+#endif
+
#include <string.h>
#include <unistd.h>
-#include <pthread.h>
#include <assert.h>
+#include <signal.h>
#include "ui.h"
#include "ui_readline.h"
@@ -49,10 +53,9 @@ THE SOFTWARE.
static inline void BarUiDoSkipSong (struct audioPlayer *player) {
assert (player != NULL);
- player->doQuit = 1;
- /* unlocking an unlocked mutex is forbidden by some implementations */
- pthread_mutex_trylock (&player->pauseMutex);
- pthread_mutex_unlock (&player->pauseMutex);
+ if (player->mode != PLAYER_FINISHED_PLAYBACK && player->mode != PLAYER_FREED) {
+ pthread_cancel (player->thread);
+ }
}
/* transform station if necessary to allow changes like rename, rate, ...
@@ -344,9 +347,12 @@ BarUiActCallback(BarUiActMoveSong) {
/* pause
*/
BarUiActCallback(BarUiActPause) {
- /* already locked => unlock/unpause */
- if (pthread_mutex_trylock (&app->player.pauseMutex) == EBUSY) {
- pthread_mutex_unlock (&app->player.pauseMutex);
+ if (app->player.paused) {
+ pthread_kill (app->player.thread, BAR_PLAYER_SIGCONT);
+ app->player.paused = false;
+ } else {
+ pthread_kill (app->player.thread, BAR_PLAYER_SIGSTOP);
+ app->player.paused = true;
}
}
@@ -489,8 +495,9 @@ BarUiActCallback(BarUiActSelectQuickMix) {
/* quit
*/
BarUiActCallback(BarUiActQuit) {
- app->doQuit = 1;
+ /* cancels player thread */
BarUiDoSkipSong (&app->player);
+ app->doQuit = 1;
}
/* song history