From 75e62269c31626b1d4fa36644fdfd98958a2699c Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Mon, 22 Jun 2020 15:40:20 +0000 Subject: [PATCH] new: hardware_concurrency helper Co-authored-by: Lorenzo Fontana Signed-off-by: Leonardo Di Donato --- userspace/engine/falco_utils.cpp | 6 ++++++ userspace/engine/falco_utils.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/userspace/engine/falco_utils.cpp b/userspace/engine/falco_utils.cpp index 44922e65..2468f905 100644 --- a/userspace/engine/falco_utils.cpp +++ b/userspace/engine/falco_utils.cpp @@ -52,6 +52,12 @@ std::string wrap_text(const std::string& str, uint32_t initial_pos, uint32_t ind return ret; } +uint32_t hardware_concurrency() +{ + auto hc = std::thread::hardware_concurrency(); + return hc ? hc : 1; +} + void readfile(const std::string& filename, std::string& data) { std::ifstream file(filename.c_str(), std::ios::in); diff --git a/userspace/engine/falco_utils.h b/userspace/engine/falco_utils.h index 25def9ad..37795e44 100644 --- a/userspace/engine/falco_utils.h +++ b/userspace/engine/falco_utils.h @@ -21,6 +21,7 @@ limitations under the License. #include #include #include +#include #include #pragma once @@ -34,6 +35,9 @@ namespace utils std::string wrap_text(const std::string& str, uint32_t initial_pos, uint32_t indent, uint32_t line_len); void readfile(const std::string& filename, std::string& data); + +uint32_t hardware_concurrency(); + namespace network { static const std::string UNIX_SCHEME("unix://");