refactor: provider hardware_concurrency wrapper

This commit is contained in:
Marcus Holland-Moritz 2024-07-27 23:23:20 +02:00
parent 9c8fd29ec2
commit bd862d1e2a
6 changed files with 12 additions and 8 deletions

View File

@ -82,4 +82,6 @@ void ensure_binary_mode(std::ostream& os);
std::string exception_str(std::exception const& e);
std::string exception_str(std::exception_ptr const& e);
unsigned int hardware_concurrency() noexcept;
} // namespace dwarfs

View File

@ -40,7 +40,6 @@
#include <folly/container/EvictingCacheMap.h>
#include <folly/container/F14Map.h>
#include <folly/stats/Histogram.h>
#include <folly/system/HardwareConcurrency.h>
#include <folly/system/ThreadName.h>
#include <dwarfs/block_cache.h>
@ -51,6 +50,7 @@
#include <dwarfs/mmif.h>
#include <dwarfs/options.h>
#include <dwarfs/performance_monitor.h>
#include <dwarfs/util.h>
namespace dwarfs {
@ -229,7 +229,7 @@ class block_cache_ final : public block_cache::impl {
wg_ = internal::worker_group(lgr, os_, "blkcache",
std::max(options.num_workers > 0
? options.num_workers
: folly::hardware_concurrency(),
: hardware_concurrency(),
static_cast<size_t>(1)));
}
}

View File

@ -38,7 +38,6 @@
#include <folly/String.h>
#include <folly/portability/Windows.h>
#include <folly/system/HardwareConcurrency.h>
#include <folly/system/ThreadName.h>
#include <dwarfs/error.h>
@ -65,7 +64,7 @@ class basic_worker_group final : public worker_group::impl, private Policy {
, pending_(0)
, max_queue_len_(max_queue_len) {
if (num_workers < 1) {
num_workers = std::max(folly::hardware_concurrency(), 1u);
num_workers = std::max(hardware_concurrency(), 1u);
}
if (!group_name) {

View File

@ -40,6 +40,7 @@
#include <folly/String.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/Windows.h>
#include <folly/system/HardwareConcurrency.h>
#include <dwarfs/error.h>
#include <dwarfs/options.h>
@ -386,4 +387,8 @@ std::string exception_str(std::exception_ptr const& e) {
return folly::exceptionStr(e).toStdString();
}
unsigned int hardware_concurrency() noexcept {
return folly::hardware_concurrency();
}
} // namespace dwarfs

View File

@ -35,7 +35,6 @@
#endif
#include <folly/portability/Unistd.h>
#include <folly/system/HardwareConcurrency.h>
#include <dwarfs/checksum.h>
#include <dwarfs/error.h>
@ -161,7 +160,7 @@ void do_checksum(logger& lgr, filesystem_v2& fs, iolayer const& iol,
} // namespace
int dwarfsck_main(int argc, sys_char** argv, iolayer const& iol) {
const size_t num_cpu = std::max(folly::hardware_concurrency(), 1u);
const size_t num_cpu = std::max(hardware_concurrency(), 1u);
auto algo_list = checksum::available_algorithms();
auto checksum_desc = fmt::format("print checksums for all files ({})",

View File

@ -51,7 +51,6 @@
#include <folly/String.h>
#include <folly/container/Enumerate.h>
#include <folly/portability/SysStat.h>
#include <folly/system/HardwareConcurrency.h>
#include <fmt/format.h>
#if FMT_VERSION >= 110000
@ -374,7 +373,7 @@ void validate(boost::any& v, std::vector<std::string> const& values,
int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
using namespace std::chrono_literals;
const size_t num_cpu = std::max(folly::hardware_concurrency(), 1u);
const size_t num_cpu = std::max(hardware_concurrency(), 1u);
static constexpr size_t const kDefaultMaxActiveBlocks{1};
static constexpr size_t const kDefaultBloomFilterSize{4};