Skip to content

Commit 417ea99

Browse files
authored
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.
1 parent 40a0e58 commit 417ea99

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

absl/base/internal/sysinfo.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ static int GetNumCPUs() {
7272
#if defined(_WIN32)
7373

7474
static double GetNominalCPUFrequency() {
75+
// UWP apps don't have access to the registry and currently don't provide an
76+
// API informing about CPU nominal frequency.
77+
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
78+
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
79+
return 1.0;
80+
#else
7581
#pragma comment(lib, "advapi32.lib") // For Reg* functions.
7682
HKEY key;
7783
// Use the Reg* functions rather than the SH functions because shlwapi.dll
@@ -91,6 +97,7 @@ static double GetNominalCPUFrequency() {
9197
}
9298
}
9399
return 1.0;
100+
#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP
94101
}
95102

96103
#elif defined(CTL_HW) && defined(HW_CPU_FREQ)

0 commit comments

Comments
 (0)