diff options
author | LC <mathew1800@gmail.com> | 2020-07-01 06:34:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 06:34:20 +0200 |
commit | 0b954a33059775c239fca2a82429b3c254d02205 (patch) | |
tree | 42cd8d08e58835e952dd111a3b326849ec86b0a4 /src/common | |
parent | Merge pull request #4209 from jbeich/webengine (diff) | |
parent | common: switch to nullptr for sysctl's empty new value (diff) | |
download | yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar.gz yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar.bz2 yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar.lz yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar.xz yuzu-0b954a33059775c239fca2a82429b3c254d02205.tar.zst yuzu-0b954a33059775c239fca2a82429b3c254d02205.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/memory_detect.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/common/memory_detect.cpp b/src/common/memory_detect.cpp index 3fdc309a2..8cff6ec37 100644 --- a/src/common/memory_detect.cpp +++ b/src/common/memory_detect.cpp @@ -9,10 +9,12 @@ // clang-format on #else #include <sys/types.h> -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) #include <sys/sysctl.h> -#else +#elif defined(__linux__) #include <sys/sysinfo.h> +#else +#include <unistd.h> #endif #endif @@ -38,15 +40,26 @@ static MemoryInfo Detect() { // hw and vm are defined in sysctl.h // https://github.com/apple/darwin-xnu/blob/master/bsd/sys/sysctl.h#L471 // sysctlbyname(const char *, void *, size_t *, void *, size_t); - sysctlbyname("hw.memsize", &ramsize, &sizeof_ramsize, NULL, 0); - sysctlbyname("vm.swapusage", &vmusage, &sizeof_vmusage, NULL, 0); + sysctlbyname("hw.memsize", &ramsize, &sizeof_ramsize, nullptr, 0); + sysctlbyname("vm.swapusage", &vmusage, &sizeof_vmusage, nullptr, 0); mem_info.TotalPhysicalMemory = ramsize; mem_info.TotalSwapMemory = vmusage.xsu_total; -#else +#elif defined(__FreeBSD__) + u_long physmem, swap_total; + std::size_t sizeof_u_long = sizeof(u_long); + // sysctlbyname(const char *, void *, size_t *, const void *, size_t); + sysctlbyname("hw.physmem", &physmem, &sizeof_u_long, nullptr, 0); + sysctlbyname("vm.swap_total", &swap_total, &sizeof_u_long, nullptr, 0); + mem_info.TotalPhysicalMemory = physmem; + mem_info.TotalSwapMemory = swap_total; +#elif defined(__linux__) struct sysinfo meminfo; sysinfo(&meminfo); mem_info.TotalPhysicalMemory = meminfo.totalram; mem_info.TotalSwapMemory = meminfo.totalswap; +#else + mem_info.TotalPhysicalMemory = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE); + mem_info.TotalSwapMemory = 0; #endif return mem_info; |