diff options
author | 2025-01-13 05:43:09 +1100 | |
---|---|---|
committer | 2025-01-13 05:43:09 +1100 | |
commit | ff92d10a0485717149b6cebc7122a3d545d48fd3 (patch) | |
tree | 735ea2a1959bcb92efa8f6b81fa72dc3494cdc38 /src/osd/modules/lib/osdlib_win32.cpp | |
parent | 43c5edd139178545db68a794bdd9ad57678098ad (diff) |
osd: Added helper for getting CPU cache line size.
Diffstat (limited to 'src/osd/modules/lib/osdlib_win32.cpp')
-rw-r--r-- | src/osd/modules/lib/osdlib_win32.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp index d42ad14d3df..cf3fd7c9320 100644 --- a/src/osd/modules/lib/osdlib_win32.cpp +++ b/src/osd/modules/lib/osdlib_win32.cpp @@ -106,6 +106,42 @@ void osd_break_into_debugger(const char *message) #endif } + +//============================================================ +// osd_get_cache_line_size +//============================================================ + +std::pair<std::error_condition, unsigned> osd_get_cache_line_size() noexcept +{ + DWORD resultsize = 0; + if (GetLogicalProcessorInformation(nullptr, &resultsize) || (ERROR_INSUFFICIENT_BUFFER != GetLastError()) || !resultsize) + return std::make_pair(std::errc::operation_not_permitted, 0U); + + auto const result = reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION *>(std::malloc(resultsize)); + if (!result) + return std::make_pair(std::errc::not_enough_memory, 0U); + + if (!GetLogicalProcessorInformation(result, &resultsize)) + { + std::free(result); + return std::make_pair(std::errc::operation_not_permitted, 0U); + } + + for (unsigned i = 0; i < (resultsize / sizeof(result[0])); ++i) + { + if ((RelationCache == result[i].Relationship) && (1 == result[i].Cache.Level)) + { + unsigned const linesize = result[i].Cache.LineSize; + std::free(result); + return std::make_pair(std::error_condition(), linesize); + } + } + + std::free(result); + return std::make_pair(std::errc::operation_not_permitted, 0U); +} + + //============================================================ // get_clipboard_text_by_format //============================================================ |