diff options
author | Jos Dehaes <jos.dehaes@gmail.com> | 2021-10-16 21:09:21 +0200 |
---|---|---|
committer | Jos Dehaes <jos.dehaes@gmail.com> | 2021-10-16 21:09:21 +0200 |
commit | c252c618c043c4b85783f56363121877d0db0727 (patch) | |
tree | d220634b7daa0a9de0bf452cd1dcdeaed952657a | |
parent | 9f88187c29821148c7a5272926d204bd3eb39f89 (diff) |
don't crash on intel
-rw-r--r-- | src/osx/sensors.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/osx/sensors.cpp b/src/osx/sensors.cpp index a3d79a6..ce3b78c 100644 --- a/src/osx/sensors.cpp +++ b/src/osx/sensors.cpp @@ -52,7 +52,7 @@ double getValue(IOHIDServiceClientRef sc) { return temp; } -} // extern C +} // extern C unordered_flat_map<int, double> Cpu::ThermalSensors::getSensors() { unordered_flat_map<int, double> cpuValues; @@ -62,29 +62,30 @@ unordered_flat_map<int, double> Cpu::ThermalSensors::getSensors() { IOHIDEventSystemClientRef system = IOHIDEventSystemClientCreate(kCFAllocatorDefault); IOHIDEventSystemClientSetMatching(system, thermalSensors); CFArrayRef matchingsrvs = IOHIDEventSystemClientCopyServices(system); - - long count = CFArrayGetCount(matchingsrvs); - for (int i = 0; i < count; i++) { - IOHIDServiceClientRef sc = (IOHIDServiceClientRef)CFArrayGetValueAtIndex(matchingsrvs, i); - if (sc) { - CFStringRef name = IOHIDServiceClientCopyProperty(sc, CFSTR("Product")); // here we use ...CopyProperty - if (name) { - char buf[200]; - CFStringGetCString(name, buf, 200, kCFStringEncodingASCII); - std::string n(buf); - if (n.starts_with("PMU tdie")) { - std::string indexString = n.substr(8, 1); - int index = stoi(indexString); - cpuValues[index - 1] = getValue(sc); - } else if (n == "SOC MTR Temp Sensor0") { - cpuValues[0] = getValue(sc); // package T for Apple Silicon + if (matchingsrvs) { + long count = CFArrayGetCount(matchingsrvs); + for (int i = 0; i < count; i++) { + IOHIDServiceClientRef sc = (IOHIDServiceClientRef)CFArrayGetValueAtIndex(matchingsrvs, i); + if (sc) { + CFStringRef name = IOHIDServiceClientCopyProperty(sc, CFSTR("Product")); // here we use ...CopyProperty + if (name) { + char buf[200]; + CFStringGetCString(name, buf, 200, kCFStringEncodingASCII); + std::string n(buf); + if (n.starts_with("PMU tdie")) { + std::string indexString = n.substr(8, 1); + int index = stoi(indexString); + cpuValues[index - 1] = getValue(sc); + } else if (n == "SOC MTR Temp Sensor0") { + cpuValues[0] = getValue(sc); // package T for Apple Silicon + } + CFRelease(name); } - CFRelease(name); } } + CFRelease(matchingsrvs); } - CFRelease(matchingsrvs); - CFRelease(system); + CFRelease(system); CFRelease(thermalSensors); return cpuValues; } |