new: hardware_concurrency helper

Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato
2020-06-22 15:40:20 +00:00
committed by poiana
parent 3d1f27d082
commit 75e62269c3
2 changed files with 10 additions and 0 deletions

View File

@@ -52,6 +52,12 @@ std::string wrap_text(const std::string& str, uint32_t initial_pos, uint32_t ind
return ret; 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) void readfile(const std::string& filename, std::string& data)
{ {
std::ifstream file(filename.c_str(), std::ios::in); std::ifstream file(filename.c_str(), std::ios::in);

View File

@@ -21,6 +21,7 @@ limitations under the License.
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <thread>
#include <nonstd/string_view.hpp> #include <nonstd/string_view.hpp>
#pragma once #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); 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); void readfile(const std::string& filename, std::string& data);
uint32_t hardware_concurrency();
namespace network namespace network
{ {
static const std::string UNIX_SCHEME("unix://"); static const std::string UNIX_SCHEME("unix://");