aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-26 08:27:04 +0200
committerMax Kellermann <max@duempel.org>2008-08-26 08:27:04 +0200
commit726c6e86d304163f0453de611ce03d656d99d1d8 (patch)
tree65bd69165d4467687487453d1e7364d4653be946
parent8d3942e0c3b4108e8968e914da75bf7c6c43f408 (diff)
downloadmpd-726c6e86d304163f0453de611ce03d656d99d1d8.tar.gz
mpd-726c6e86d304163f0453de611ce03d656d99d1d8.tar.xz
mpd-726c6e86d304163f0453de611ce03d656d99d1d8.zip
don't busy wait for the decoder thread
Busy wait loops are a bad thing, especially when the response time can be very long - busy waits eat a lot of CPU, and thus slow down the other thread. Since the other thread will notify us when it's ready, we can use notify_wait() instead.
-rw-r--r--src/decode.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/decode.c b/src/decode.c
index 02f806488..551f40caa 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -58,8 +58,10 @@ static void player_wakeup_decoder(void)
static void dc_command_wait(void)
{
- while (dc.command != DECODE_COMMAND_NONE)
+ while (dc.command != DECODE_COMMAND_NONE) {
player_wakeup_decoder_nb();
+ notify_wait(&pc.notify);
+ }
}
static void dc_command(enum decoder_command cmd)
@@ -112,8 +114,10 @@ static unsigned calculateCrossFadeChunks(AudioFormat * af, float totalTime)
static int waitOnDecode(int *decodeWaitedOn)
{
- while (dc.command == DECODE_COMMAND_START)
- player_wakeup_decoder();
+ while (dc.command == DECODE_COMMAND_START) {
+ notify_signal(&dc.notify);
+ notify_wait(&pc.notify);
+ }
if (dc.error != DECODE_ERROR_NOERROR) {
pc.errored_song = dc.next_song;