mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 22:23:52 +00:00
Prevent concurrent modification of host list
This commit is contained in:
@@ -77,8 +77,11 @@
|
|||||||
Log(LOG_I, @"Starting discovery");
|
Log(LOG_I, @"Starting discovery");
|
||||||
shouldDiscover = YES;
|
shouldDiscover = YES;
|
||||||
[_mdnsMan searchForHosts];
|
[_mdnsMan searchForHosts];
|
||||||
for (TemporaryHost* host in _hostQueue) {
|
|
||||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
@synchronized (_hostQueue) {
|
||||||
|
for (TemporaryHost* host in _hostQueue) {
|
||||||
|
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,21 +144,26 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[_hostQueue addObject:host];
|
@synchronized (_hostQueue) {
|
||||||
if (shouldDiscover) {
|
[_hostQueue addObject:host];
|
||||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
if (shouldDiscover) {
|
||||||
|
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeHostFromDiscovery:(TemporaryHost *)host {
|
- (void) removeHostFromDiscovery:(TemporaryHost *)host {
|
||||||
for (DiscoveryWorker* worker in [_opQueue operations]) {
|
@synchronized (_hostQueue) {
|
||||||
if ([worker getHost] == host) {
|
for (DiscoveryWorker* worker in [_opQueue operations]) {
|
||||||
[worker cancel];
|
if ([worker getHost] == host) {
|
||||||
|
[worker cancel];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[_hostQueue removeObject:host];
|
||||||
}
|
}
|
||||||
[_hostQueue removeObject:host];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override from MDNSCallback - called in a worker thread
|
// Override from MDNSCallback - called in a worker thread
|
||||||
@@ -167,16 +175,20 @@
|
|||||||
[worker discoverHost];
|
[worker discoverHost];
|
||||||
if ([self addHostToDiscovery:host]) {
|
if ([self addHostToDiscovery:host]) {
|
||||||
Log(LOG_I, @"Found new host through MDNS: %@:", host.name);
|
Log(LOG_I, @"Found new host through MDNS: %@:", host.name);
|
||||||
[self->_callback updateAllHosts:self->_hostQueue];
|
@synchronized (_hostQueue) {
|
||||||
|
[_callback updateAllHosts:_hostQueue];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log(LOG_D, @"Found existing host through MDNS: %@", host.name);
|
Log(LOG_D, @"Found existing host through MDNS: %@", host.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (TemporaryHost*) getHostInDiscovery:(NSString*)uuidString {
|
- (TemporaryHost*) getHostInDiscovery:(NSString*)uuidString {
|
||||||
for (TemporaryHost* discoveredHost in _hostQueue) {
|
@synchronized (_hostQueue) {
|
||||||
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:uuidString]) {
|
for (TemporaryHost* discoveredHost in _hostQueue) {
|
||||||
return discoveredHost;
|
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:uuidString]) {
|
||||||
|
return discoveredHost;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
|||||||
Reference in New Issue
Block a user