1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_SYSTEM_SYS_INFO_INTERNAL_H_ 6 #define BASE_SYSTEM_SYS_INFO_INTERNAL_H_ 7 8 #include "base/base_export.h" 9 #include "build/build_config.h" 10 11 #if BUILDFLAG(IS_APPLE) 12 #include <optional> 13 #endif 14 15 namespace base { 16 17 namespace internal { 18 19 template <typename T, T (*F)(void)> 20 class LazySysInfoValue { 21 public: LazySysInfoValue()22 LazySysInfoValue() : value_(F()) {} 23 24 LazySysInfoValue(const LazySysInfoValue&) = delete; 25 LazySysInfoValue& operator=(const LazySysInfoValue&) = delete; 26 27 ~LazySysInfoValue() = default; 28 value()29 T value() { return value_; } 30 31 private: 32 const T value_; 33 }; 34 35 #if BUILDFLAG(IS_MAC) 36 // Exposed for testing. 37 BASE_EXPORT std::optional<int> NumberOfPhysicalProcessors(); 38 39 // When CPU security mitigation is enabled, return number of "physical" 40 // cores and not the number of "logical" cores. CPU security mitigations 41 // disables hyper-threading for the current application, which effectively 42 // limits the number of concurrently executing threads to the number of 43 // physical cores. 44 std::optional<int> NumberOfProcessorsWhenCpuSecurityMitigationEnabled(); 45 #endif 46 47 #if BUILDFLAG(IS_APPLE) 48 std::optional<int> GetSysctlIntValue(const char* key_name); 49 #endif 50 51 } // namespace internal 52 53 } // namespace base 54 55 #endif // BASE_SYSTEM_SYS_INFO_INTERNAL_H_ 56