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:
AntiCat 2018-10-08 07:15:29 +02:00 committed by pwpiwi
commit 2a53731106
5 changed files with 80 additions and 5 deletions

View file

@ -18,6 +18,7 @@
#include "uart.h"
#include "ui.h"
#include "common.h"
#include "util_darwin.h"
#include "util_posix.h"
@ -198,6 +199,10 @@ __attribute__((force_align_arg_pointer))
UsbCommand rx;
UsbCommand *prx = ℞
#if defined(__MACH__) && defined(__APPLE__)
disableAppNap("Proxmark3 polling UART");
#endif
while (conn->run) {
rxlen = 0;
bool ACK_received = false;
@ -236,6 +241,10 @@ __attribute__((force_align_arg_pointer))
pthread_mutex_unlock(&txBufferMutex);
}
#if defined(__MACH__) && defined(__APPLE__)
enableAppNap();
#endif
pthread_exit(NULL);
return NULL;
}