Last active
March 26, 2019 09:39
-
-
Save steipete/3e781cf061ff166eb5622d4d275da84c to your computer and use it in GitHub Desktop.
PSPDFApplicationIsTerminating - detect application termination on iOS and macOS. License: MIT. Taken out of the commercial PSPDFKit PDF SDK. http://pspdfkit.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static _Atomic(BOOL) _applicationWillTerminate = NO; | |
__attribute__((constructor)) static void PSPDFInstallAppWillTerminateHandler(void) { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
[NSNotificationCenter.defaultCenter addObserverForName:UIApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification *note) { | |
_applicationWillTerminate = YES; | |
PSPDFLogWarning(@"Application shutdown event detected."); | |
}]; | |
}); | |
} | |
PSPDF_EXTERN BOOL PSPDFApplicationIsTerminating(void) { | |
return _applicationWillTerminate; | |
} |
I got confused for a second. It's been a while since I used atomic_fetch_add
/atomic_fetch_sub
. Is the default relax order relaxed
?
If I understand correctly, what I really want is memory_order_seq_cst
, which is then the order that is used by _Atomic(XXX)
, which also has a nicer syntax.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ouch! TIL indeed!
Thanks!