[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:
Christopher Snowhill 2022-06-17 18:02:32 -07:00
parent 4b4776fbc0
commit e334d8a017
2 changed files with 11 additions and 6 deletions

View file

@ -49,7 +49,7 @@
- (void)process; // Should be overwriten by subclass
- (void)threadEntry:(id _Nullable)arg;
- (void)followWorkgroup;
- (BOOL)followWorkgroup;
- (void)leaveWorkgroup;
- (void)startWorkslice;
- (void)endWorkslice;

View file

@ -205,13 +205,14 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
- (void)threadEntry:(id)arg {
@autoreleasepool {
[self followWorkgroup];
[self process];
[self leaveWorkgroup];
if([self followWorkgroup]) {
[self process];
[self leaveWorkgroup];
}
}
}
- (void)followWorkgroup {
- (BOOL)followWorkgroup {
if(@available(macOS 11, *)) {
if(!wg) {
if(!workgroup) {
@ -223,20 +224,24 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
if(wg && !isRealtimeError) {
int result = os_workgroup_join(wg, &wgToken);
isDeadlineError = NO;
if(result == 0) return;
if(result == 0) return YES;
if(result == EALREADY) {
DLog(@"Thread already in workgroup");
return NO;
} else {
DLog(@"Cannot join workgroup, error %d", result);
isRealtimeError = YES;
return NO;
}
}
}
return wg != nil && !isRealtimeError;
} else {
if(!isRealtime && !isRealtimeError) {
isRealtimeError = SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self()));
isRealtime = !isRealtimeError;
}
return YES;
}
}