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 <kode54@gmail.com>CQTexperiment
parent
be6fda4663
commit
4f5e5a9e4e
|
@ -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<uint8_t> &bufferRef) {
|
||||
id<CogSource> 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<uint8_t> &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<uint8_t> &bufferRef)
|
|||
|
||||
if(!usedHint)
|
||||
[source close];
|
||||
|
||||
[_lock unlock];
|
||||
}
|
||||
|
||||
@implementation SidDecoder
|
||||
|
|
Loading…
Reference in New Issue