mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 21:33:19 -07:00
osx: disable app-nap during serial comm (#687)
Apple introduced app-nap with OS X 10.10. This feature saves power by throttling apps running in background. However, it also less accurate timers in systemcalls. In our case a 30ms select timeout would take up to 10s. This patch uses an API also added with 10.10 to disable app-nap as long as the serial port is polled.
This commit is contained in:
parent
70b2fc0abd
commit
2a53731106
5 changed files with 80 additions and 5 deletions
40
client/util_darwin.m
Normal file
40
client/util_darwin.m
Normal file
|
@ -0,0 +1,40 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// (c) 2018 AntiCat
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// macOS framework bindings
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#import "util_darwin.h"
|
||||
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
static id activity = nil;
|
||||
|
||||
//OS X Version 10.10 is defined in OS X 10.10 and later
|
||||
#if defined(MAC_OS_X_VERSION_10_10)
|
||||
void disableAppNap(const char* reason) {
|
||||
if(activity == nil) {
|
||||
//NSLog(@"disableAppNap: %@", @(reason));
|
||||
activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityBackground reason:@(reason)];
|
||||
[activity retain];
|
||||
}
|
||||
}
|
||||
|
||||
void enableAppNap() {
|
||||
if(activity != nil) {
|
||||
//NSLog(@"enableAppNap");
|
||||
[[NSProcessInfo processInfo] endActivity:activity];
|
||||
[activity release];
|
||||
activity = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void disableAppNap(const char* reason) { }
|
||||
void enableAppNap() { }
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue