aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-08-23 21:06:11 -0700
committerEric Wong <normalperson@yhbt.net>2008-08-23 21:06:11 -0700
commit8439e0ce44b895931fd821da5a31fa53e3fcd421 (patch)
treeae26478cf5f35edbde4c5be43f7d8dce2a8d6e74 /src
parentd9eaeafe7c404d3e48961ddfcd8cee7299a3fa76 (diff)
downloadmpd-8439e0ce44b895931fd821da5a31fa53e3fcd421.tar.gz
mpd-8439e0ce44b895931fd821da5a31fa53e3fcd421.tar.xz
mpd-8439e0ce44b895931fd821da5a31fa53e3fcd421.zip
xfade: copy xfade_time locally to avoid race conditions
ob.xfade_time can be changed by the main process without locking, so copy the float value into a local variable and recheck the local variable for zero before continuing.
Diffstat (limited to '')
-rw-r--r--src/outputBuffer_xfade.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/outputBuffer_xfade.h b/src/outputBuffer_xfade.h
index a2a6b0c38..48084c44b 100644
--- a/src/outputBuffer_xfade.h
+++ b/src/outputBuffer_xfade.h
@@ -8,6 +8,7 @@
static struct ob_chunk *get_chunk(struct iovec vec[2], size_t i);
static size_t calculate_xfade_chunks(struct iovec vec[2])
{
+ float xfade_time = ob.xfade_time; /* prevent race conditions */
size_t chunks;
struct ob_chunk *c;
size_t nr;
@@ -15,11 +16,13 @@ static size_t calculate_xfade_chunks(struct iovec vec[2])
assert(pthread_equal(ob.thread, pthread_self()));
+ if (xfade_time <= 0)
+ return ob.bpp_cur;
if (!isCurrentAudioFormat(af))
return 0;
if (!ob.total_time ||
- (ob.elapsed_time + ob.xfade_time) < ob.total_time)
+ (ob.elapsed_time + xfade_time) < ob.total_time)
return ob.bpp_cur; /* too early, don't enable xfade yet */
assert(af->bits > 0);
@@ -27,7 +30,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2])
assert(af->sampleRate > 0);
chunks = af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE;
- chunks = chunks * (ob.xfade_time + 0.5);
+ chunks = chunks * (xfade_time + 0.5);
assert(chunks);
assert(ob.index->size >= ob.bpp_cur);