Audio Player: Only wait for unstopped input

Input thread now signals when it has stopped and is about to return, in
case the input thread returns before the BufferChain dealloc function
would be waiting for it to terminate. Somehow, even though the Semaphore
is being signaled at this point, the BufferChain still ends up waiting
the default of 2.5 seconds for the signal that apparently never comes,
delaying file stoppage. This prevents the wait action entirely. Must
have been some sort of race condition.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
main
Christopher Snowhill 2022-12-09 21:17:45 -08:00
parent 447a60afd9
commit 9822dcc4c0
No known key found for this signature in database
3 changed files with 6 additions and 1 deletions

View File

@ -156,7 +156,8 @@
[inputNode setShouldContinue:NO];
[[inputNode exitAtTheEndOfTheStream] signal];
[[inputNode semaphore] signal];
[[inputNode exitAtTheEndOfTheStream] wait]; // wait for decoder to be closed (see InputNode's -(void)process )
if(![inputNode threadExited])
[[inputNode exitAtTheEndOfTheStream] wait]; // wait for decoder to be closed (see InputNode's -(void)process )
DLog(@"Bufferchain dealloc");
}

View File

@ -34,6 +34,7 @@
Semaphore *exitAtTheEndOfTheStream;
}
@property(readonly) Semaphore *exitAtTheEndOfTheStream;
@property(readonly) BOOL threadExited;
- (BOOL)openWithSource:(id<CogSource>)source;
- (BOOL)openWithDecoder:(id<CogDecoder>)d;

View File

@ -21,12 +21,14 @@
static void *kInputNodeContext = &kInputNodeContext;
@synthesize threadExited;
@synthesize exitAtTheEndOfTheStream;
- (id)initWithController:(id)c previous:(id)p {
self = [super initWithController:c previous:p];
if(self) {
exitAtTheEndOfTheStream = [[Semaphore alloc] init];
threadExited = NO;
}
return self;
@ -223,6 +225,7 @@ static void *kInputNodeContext = &kInputNodeContext;
[decoder close];
[exitAtTheEndOfTheStream signal];
threadExited = YES;
DLog("Input node thread stopping");
}