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 "third_party/abseil-cpp/absl/types/optional.h" 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 absl::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 absl::optional<int> NumberOfProcessorsWhenCpuSecurityMitigationEnabled(); 45 #endif 46 47 // Exposed for testing. 48 BASE_EXPORT int NumberOfProcessors(); 49 50 #if BUILDFLAG(IS_APPLE) 51 absl::optional<int> GetSysctlIntValue(const char* key_name); 52 #endif 53 54 } // namespace internal 55 56 } // namespace base 57 58 #endif // BASE_SYSTEM_SYS_INFO_INTERNAL_H_ 59