From fc9069d7c744679e3ea3f227ccf3e65af5cf68ac Mon Sep 17 00:00:00 2001 From: vspader Date: Sat, 13 Oct 2007 08:14:05 +0000 Subject: [PATCH] Fixed unguarded critical sections. --- Audio/AudioPlayer.m | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 58c66acaa..8766808a6 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -54,20 +54,23 @@ output = [[OutputNode alloc] initWithController:self previous:nil]; [output setup]; - NSEnumerator *enumerator = [chainQueue objectEnumerator]; - id anObject; - while (anObject = [enumerator nextObject]) - { - [anObject setShouldContinue:NO]; - } - [chainQueue removeAllObjects]; - - if (bufferChain) - { - [bufferChain setShouldContinue:NO]; + @synchronized(chainQueue) { + NSEnumerator *enumerator = [chainQueue objectEnumerator]; + id anObject; + while (anObject = [enumerator nextObject]) + { + [anObject setShouldContinue:NO]; + } + [chainQueue removeAllObjects]; + + if (bufferChain) + { + [bufferChain setShouldContinue:NO]; - [bufferChain release]; + [bufferChain release]; + } } + bufferChain = [[BufferChain alloc] initWithController:self]; while (![bufferChain open:url withOutputFormat:[output format]]) @@ -263,13 +266,15 @@ return; } - bufferChain = [chainQueue objectAtIndex:0]; - [bufferChain retain]; + @synchronized(chainQueue) { + bufferChain = [chainQueue objectAtIndex:0]; + [bufferChain retain]; + + NSLog(@"New!!! %@ %@", bufferChain, [[bufferChain inputNode] decoder]); + + [chainQueue removeObjectAtIndex:0]; + } - NSLog(@"New!!! %@ %@", bufferChain, [[bufferChain inputNode] decoder]); - - [chainQueue removeObjectAtIndex:0]; - [self notifyStreamChanged:[bufferChain userInfo]]; [output setEndOfStream:NO]; }