Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/os/osx/ocpu.cpp
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
Show All 12 Lines | |||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "lib/sysdep/os_cpu.h" | #include "lib/sysdep/os_cpu.h" | ||||
#include "lib/alignment.h" | #include "lib/alignment.h" | ||||
#include "lib/bits.h" | #include "lib/bits.h" | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/types.h> | |||||
size_t os_cpu_NumProcessors() | size_t os_cpu_NumProcessors() | ||||
{ | { | ||||
static size_t numProcessors; | static size_t numProcessors; | ||||
if(numProcessors == 0) | if(numProcessors == 0) | ||||
{ | { | ||||
// Mac OS X doesn't have sysconf(_SC_NPROCESSORS_CONF) | // Mac OS X doesn't have sysconf(_SC_NPROCESSORS_CONF) | ||||
Show All 35 Lines | |||||
{ | { | ||||
// assume they're unsupported. | // assume they're unsupported. | ||||
return 0; | return 0; | ||||
} | } | ||||
size_t os_cpu_QueryMemorySize() | size_t os_cpu_QueryMemorySize() | ||||
{ | { | ||||
size_t memorySize = 0; | int64_t memorySize = 0; | ||||
vladislavbelov: `sysctl` uses `size_t`, so it should be at least `uint64_t`. Also why it's clamped? Do we… | |||||
StanAuthorUnsubmitted Done Inline ActionsI used the example on stackoverflow assuming the code we had was wrong. On macos we don't support 32bits. Stan: I used the example on stackoverflow assuming the code we had was wrong. On macos we don't… | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsIf we don't plan to support 32-bit macOS then just leave size_t, int64_t is incorrect size. vladislavbelov: If we don't plan to support 32-bit macOS then just leave `size_t`, `int64_t` is incorrect size. | |||||
size_t len = sizeof(memorySize); | size_t len = sizeof(memorySize); | ||||
// Argh, the API doesn't seem to be const-correct | // Argh, the API doesn't seem to be const-correct | ||||
/*const*/ int mib[2] = { CTL_HW, HW_PHYSMEM }; | /*const*/ int mib[2] = { CTL_HW, HW_MEMSIZE }; | ||||
sysctl(mib, 2, &memorySize, &len, 0, 0); | sysctl(mib, 2, &memorySize, &len, nullptr, 0); | ||||
memorySize /= MiB; | memorySize /= MiB; | ||||
return memorySize; | return memorySize; | ||||
} | } | ||||
size_t os_cpu_MemoryAvailable() | size_t os_cpu_MemoryAvailable() | ||||
{ | { | ||||
size_t memoryAvailable = 0; | int64_t memoryAvailable = 0; | ||||
size_t len = sizeof(memoryAvailable); | size_t len = sizeof(memoryAvailable); | ||||
// Argh, the API doesn't seem to be const-correct | // Argh, the API doesn't seem to be const-correct | ||||
/*const*/ int mib[2] = { CTL_HW, HW_USERMEM }; | /*const*/ int mib[2] = { CTL_HW, HW_USERMEM }; | ||||
sysctl(mib, 2, &memoryAvailable, &len, 0, 0); | sysctl(mib, 2, &memoryAvailable, &len, nullptr, 0); | ||||
memoryAvailable /= MiB; | memoryAvailable /= MiB; | ||||
return memoryAvailable; | return memoryAvailable; | ||||
} | } | ||||
uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t UNUSED(processorMask)) | uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t UNUSED(processorMask)) | ||||
{ | { | ||||
// not yet implemented. when doing so, see http://developer.apple.com/releasenotes/Performance/RN-AffinityAPI/ | // not yet implemented. when doing so, see http://developer.apple.com/releasenotes/Performance/RN-AffinityAPI/ | ||||
Show All 16 Lines |
Wildfire Games · Phabricator
sysctl uses size_t, so it should be at least uint64_t. Also why it's clamped? Do we support 32-bit mac? And what's the size of size_t there?