Skip to content

Commit

Permalink
cache std::thread::hardware_concurrency() result at start up
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Aug 13, 2024
1 parent a562439 commit 244abdb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/destroy_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class destroy_manager {
std::size_t expected{
destroy_threads_num_.load(std::memory_order_acquire)};
for (;;) {
if (expected >= std::thread::hardware_concurrency()) {
if (expected >= hardware_concurrency_) {
return false;
}
std::size_t desired = expected + 1;
Expand All @@ -34,6 +34,7 @@ class destroy_manager {

private:
static inline std::atomic<std::size_t> destroy_threads_num_{0}; // NOLINT
static inline std::size_t hardware_concurrency_{std::thread::hardware_concurrency()}; // NOLINT
};

} // namespace yakushima

0 comments on commit 244abdb

Please sign in to comment.