From 417ea99cbac80c85be9f52c8b482f15d47bee93e Mon Sep 17 00:00:00 2001 From: Augusto Righetto Date: Mon, 9 Mar 2020 05:55:40 -0700 Subject: UWP doesn't allow reading regkeys (#594) * UWP doesn't allow reading regkeys. Unfortunately, UWP also doesn't offer an API for returning nominal processor frequency at this moment. Other options would require apps depending on abseil-cpp to be packaged with extra manifest data or libraries for bridging platforms. This change pushes the unsupported APIs accessing the registry behind a define guard. This define guard makes GetNominalCPUFrequency to compile and run as usual on desktop, but it will return the value 1.0 on UWP Apps (Store). * Using WINAPI_FAMILY_PARTITION family of macros for detecting when building for UWP or Desktop. * Simplifying comment to please the lint tool. --- absl/base/internal/sysinfo.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'absl/base') diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc index a0930e978183..2ec5793026bd 100644 --- a/absl/base/internal/sysinfo.cc +++ b/absl/base/internal/sysinfo.cc @@ -72,6 +72,12 @@ static int GetNumCPUs() { #if defined(_WIN32) static double GetNominalCPUFrequency() { +// UWP apps don't have access to the registry and currently don't provide an +// API informing about CPU nominal frequency. +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + return 1.0; +#else #pragma comment(lib, "advapi32.lib") // For Reg* functions. HKEY key; // Use the Reg* functions rather than the SH functions because shlwapi.dll @@ -91,6 +97,7 @@ static double GetNominalCPUFrequency() { } } return 1.0; +#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP } #elif defined(CTL_HW) && defined(HW_CPU_FREQ) -- cgit 1.4.1