[Audio Threads] Apply changes to workgroup handler
Apply changes to exit the thread if workgroup initialization or joining fails, instead of attempting to continue executing the thread. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
4b4776fbc0
commit
e334d8a017
2 changed files with 11 additions and 6 deletions
|
@ -49,7 +49,7 @@
|
||||||
- (void)process; // Should be overwriten by subclass
|
- (void)process; // Should be overwriten by subclass
|
||||||
- (void)threadEntry:(id _Nullable)arg;
|
- (void)threadEntry:(id _Nullable)arg;
|
||||||
|
|
||||||
- (void)followWorkgroup;
|
- (BOOL)followWorkgroup;
|
||||||
- (void)leaveWorkgroup;
|
- (void)leaveWorkgroup;
|
||||||
- (void)startWorkslice;
|
- (void)startWorkslice;
|
||||||
- (void)endWorkslice;
|
- (void)endWorkslice;
|
||||||
|
|
|
@ -205,13 +205,14 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
|
||||||
|
|
||||||
- (void)threadEntry:(id)arg {
|
- (void)threadEntry:(id)arg {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
[self followWorkgroup];
|
if([self followWorkgroup]) {
|
||||||
[self process];
|
[self process];
|
||||||
[self leaveWorkgroup];
|
[self leaveWorkgroup];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)followWorkgroup {
|
- (BOOL)followWorkgroup {
|
||||||
if(@available(macOS 11, *)) {
|
if(@available(macOS 11, *)) {
|
||||||
if(!wg) {
|
if(!wg) {
|
||||||
if(!workgroup) {
|
if(!workgroup) {
|
||||||
|
@ -223,20 +224,24 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
|
||||||
if(wg && !isRealtimeError) {
|
if(wg && !isRealtimeError) {
|
||||||
int result = os_workgroup_join(wg, &wgToken);
|
int result = os_workgroup_join(wg, &wgToken);
|
||||||
isDeadlineError = NO;
|
isDeadlineError = NO;
|
||||||
if(result == 0) return;
|
if(result == 0) return YES;
|
||||||
if(result == EALREADY) {
|
if(result == EALREADY) {
|
||||||
DLog(@"Thread already in workgroup");
|
DLog(@"Thread already in workgroup");
|
||||||
|
return NO;
|
||||||
} else {
|
} else {
|
||||||
DLog(@"Cannot join workgroup, error %d", result);
|
DLog(@"Cannot join workgroup, error %d", result);
|
||||||
isRealtimeError = YES;
|
isRealtimeError = YES;
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return wg != nil && !isRealtimeError;
|
||||||
} else {
|
} else {
|
||||||
if(!isRealtime && !isRealtimeError) {
|
if(!isRealtime && !isRealtimeError) {
|
||||||
isRealtimeError = SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self()));
|
isRealtimeError = SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self()));
|
||||||
isRealtime = !isRealtimeError;
|
isRealtime = !isRealtimeError;
|
||||||
}
|
}
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue