mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-03 06:26:09 +00:00
Fix concurrency issues accessing TemporaryHost fields that could be changed by other threads
This commit is contained in:
@@ -11,24 +11,24 @@
|
||||
|
||||
@interface TemporaryHost : NSObject
|
||||
|
||||
@property (nonatomic) State state;
|
||||
@property (nonatomic) PairState pairState;
|
||||
@property (nonatomic, nullable) NSString * activeAddress;
|
||||
@property (nonatomic, nullable) NSString * currentGame;
|
||||
@property (atomic) State state;
|
||||
@property (atomic) PairState pairState;
|
||||
@property (atomic, nullable, retain) NSString * activeAddress;
|
||||
@property (atomic, nullable, retain) NSString * currentGame;
|
||||
|
||||
@property (nonatomic, nullable, retain) NSData *serverCert;
|
||||
@property (nonatomic, nullable, retain) NSString *address;
|
||||
@property (nonatomic, nullable, retain) NSString *externalAddress;
|
||||
@property (nonatomic, nullable, retain) NSString *localAddress;
|
||||
@property (nonatomic, nullable, retain) NSString *ipv6Address;
|
||||
@property (nonatomic, nullable, retain) NSString *mac;
|
||||
@property (nonatomic) int serverCodecModeSupport;
|
||||
@property (atomic, nullable, retain) NSData *serverCert;
|
||||
@property (atomic, nullable, retain) NSString *address;
|
||||
@property (atomic, nullable, retain) NSString *externalAddress;
|
||||
@property (atomic, nullable, retain) NSString *localAddress;
|
||||
@property (atomic, nullable, retain) NSString *ipv6Address;
|
||||
@property (atomic, nullable, retain) NSString *mac;
|
||||
@property (atomic) int serverCodecModeSupport;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property (nonatomic, retain) NSString *name;
|
||||
@property (nonatomic, retain) NSString *uuid;
|
||||
@property (nonatomic, retain) NSMutableSet *appList;
|
||||
@property (atomic, retain) NSString *name;
|
||||
@property (atomic, retain) NSString *uuid;
|
||||
@property (atomic, retain) NSSet *appList;
|
||||
|
||||
- (id) initFromHost:(Host*)host;
|
||||
|
||||
|
||||
@@ -192,10 +192,11 @@ static NSMutableSet* hostList;
|
||||
|
||||
- (void) updateApplist:(NSSet*) newList forHost:(TemporaryHost*)host {
|
||||
DataManager* database = [[DataManager alloc] init];
|
||||
NSMutableSet* newHostAppList = [NSMutableSet setWithSet:host.appList];
|
||||
|
||||
for (TemporaryApp* app in newList) {
|
||||
BOOL appAlreadyInList = NO;
|
||||
for (TemporaryApp* savedApp in host.appList) {
|
||||
for (TemporaryApp* savedApp in newHostAppList) {
|
||||
if ([app.id isEqualToString:savedApp.id]) {
|
||||
savedApp.name = app.name;
|
||||
savedApp.hdrSupported = app.hdrSupported;
|
||||
@@ -205,7 +206,7 @@ static NSMutableSet* hostList;
|
||||
}
|
||||
if (!appAlreadyInList) {
|
||||
app.host = host;
|
||||
[host.appList addObject:app];
|
||||
[newHostAppList addObject:app];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +214,7 @@ static NSMutableSet* hostList;
|
||||
do {
|
||||
appWasRemoved = NO;
|
||||
|
||||
for (TemporaryApp* app in host.appList) {
|
||||
for (TemporaryApp* app in newHostAppList) {
|
||||
appWasRemoved = YES;
|
||||
for (TemporaryApp* mergedApp in newList) {
|
||||
if ([mergedApp.id isEqualToString:app.id]) {
|
||||
@@ -225,7 +226,7 @@ static NSMutableSet* hostList;
|
||||
// Removing the app mutates the list we're iterating (which isn't legal).
|
||||
// We need to jump out of this loop and restart enumeration.
|
||||
|
||||
[host.appList removeObject:app];
|
||||
[newHostAppList removeObject:app];
|
||||
|
||||
// It's important to remove the app record from the database
|
||||
// since we'll have a constraint violation now that appList
|
||||
@@ -238,6 +239,8 @@ static NSMutableSet* hostList;
|
||||
|
||||
// Keep looping until the list is no longer being mutated
|
||||
} while (appWasRemoved);
|
||||
|
||||
host.appList = newHostAppList;
|
||||
|
||||
[database updateAppsForExistingHost:host];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user