Merge branch 'battery-macos' of https://github.com/jtgrassie/xmrig into dev

This commit is contained in:
XMRig 2020-08-20 12:46:09 +07:00
commit f06e30e343
No known key found for this signature in database
GPG key ID: 446A53638BE94409
2 changed files with 5 additions and 11 deletions

View file

@ -143,6 +143,8 @@ elseif (XMRIG_OS_APPLE)
src/App_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp
)
find_library(IOKIT_LIBRARY IOKit)
set(EXTRA_LIBS ${IOKIT_LIBRARY})
else()
list(APPEND SOURCES_OS
src/App_unix.cpp

View file

@ -22,6 +22,8 @@
*/
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPowerSources.h>
#include <mach/thread_act.h>
#include <mach/thread_policy.h>
#include <stdio.h>
@ -111,15 +113,5 @@ void xmrig::Platform::setThreadPriority(int priority)
bool xmrig::Platform::isOnBatteryPower()
{
for (int i = 0; i <= 1; ++i) {
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
}