Skip to content

Commit

Permalink
Grab therman state from a background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kstenerud committed Jan 11, 2023
1 parent 8f89a59 commit 88a8dda
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Bugsnag/Helpers/BSGRunContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ static void NoteThermalState(__unused CFNotificationCenterRef center,
__unused CFNotificationName name,
const void *object,
__unused CFDictionaryRef userInfo) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
bsg_runContext->thermalState = ((__bridge NSProcessInfo *)object).thermalState;
#pragma clang diagnostic pop
BSGRunContextUpdateTimestamp();
if (@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)) {
// Workaround for iOS 15.0.2 to 15.1.1: Foundation in rare cases posts
// ThermalStateDidChangeNotification from within -[NSProcessInfo thermalState],
// causing recursion and a crash via _os_unfair_lock_recursive_abort().
// To avoid this, grab the new thermal state asynchronously.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
bsg_runContext->thermalState = ((__bridge NSProcessInfo *)object).thermalState;
BSGRunContextUpdateTimestamp();
});
}
}

#if BSG_HAVE_OOM_DETECTION
Expand Down

0 comments on commit 88a8dda

Please sign in to comment.