From 4f5e5a9e4e0498c7b1e2353abf2372ab83b67457 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 11 Feb 2022 03:56:50 -0800 Subject: [PATCH] SID Input: Synchronize cross file access The same file may be accessed from other threads, thanks to this cache thing. Synchronize access so that only one thread is reading the file at a time. Signed-off-by: Christopher Snowhill --- Plugins/sidplay/SidDecoder.mm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Plugins/sidplay/SidDecoder.mm b/Plugins/sidplay/SidDecoder.mm index b6cf37d83..d5580c3f3 100644 --- a/Plugins/sidplay/SidDecoder.mm +++ b/Plugins/sidplay/SidDecoder.mm @@ -21,6 +21,8 @@ static const char *extListEmpty[] = { NULL }; static const char *extListStr[] = { ".str", NULL }; +static NSLock *_lock = [[NSLock alloc] init]; + @interface sid_file_container : NSObject { NSLock *lock; NSMutableDictionary *list; @@ -76,6 +78,7 @@ static const char *extListStr[] = { ".str", NULL }; static void sidTuneLoader(const char *fileName, std::vector &bufferRef) { id source; BOOL usedHint = YES; + [_lock lock]; if(![[sid_file_container instance] try_hint:[NSString stringWithUTF8String:fileName] source:&source]) { usedHint = NO; @@ -85,11 +88,15 @@ static void sidTuneLoader(const char *fileName, std::vector &bufferRef) id audioSourceClass = NSClassFromString(@"AudioSource"); source = [audioSourceClass audioSourceForURL:url]; - if(![source open:url]) + if(![source open:url]) { + [_lock unlock]; return; + } - if(![source seekable]) + if(![source seekable]) { + [_lock unlock]; return; + } } [source seek:0 whence:SEEK_END]; @@ -102,6 +109,8 @@ static void sidTuneLoader(const char *fileName, std::vector &bufferRef) if(!usedHint) [source close]; + + [_lock unlock]; } @implementation SidDecoder