mirror of
https://github.com/anrieff/libcpuid
synced 2025-01-23 20:06:41 +00:00
Added CPU clock OS detection routine for Mac OS X
git-svn-id: https://svn.code.sf.net/p/libcpuid/code/HEAD/libcpuid@48 3b4be424-7ac5-41d7-8526-f4ddcb85d872
This commit is contained in:
parent
82c5d8f66a
commit
1fe1729a1f
1 changed files with 14 additions and 0 deletions
|
@ -107,6 +107,19 @@ int cpu_clock_by_os(void)
|
|||
return (int)result;
|
||||
}
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
/* Assuming Mac OS X with hw.cpufrequency sysctl */
|
||||
int cpu_clock_by_os(void)
|
||||
{
|
||||
long long result = -1;
|
||||
size_t size = sizeof(result);
|
||||
if (sysctlbyname("hw.cpufrequency", &result, &size, NULL, 0))
|
||||
return -1;
|
||||
return (int) (result / (long long) 1000000);
|
||||
}
|
||||
#else
|
||||
/* Assuming Linux with /proc/cpuinfo */
|
||||
int cpu_clock_by_os(void)
|
||||
{
|
||||
|
@ -129,6 +142,7 @@ int cpu_clock_by_os(void)
|
|||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* Emulate doing useful CPU intensive work */
|
||||
|
|
Loading…
Reference in a new issue