From 8caae219cffc33d2986f2ef5ab8c7dd5e180ea36 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 14 Oct 2014 10:33:10 -0400 Subject: [PATCH] Gracefully cast from std::thread::hardware_concurrency --- src/beast/beast/module/core/thread/Workers.h | 3 ++- src/ripple/core/impl/JobQueue.cpp | 14 ++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/beast/beast/module/core/thread/Workers.h b/src/beast/beast/module/core/thread/Workers.h index 0fb8daf15..0f54ca3e0 100644 --- a/src/beast/beast/module/core/thread/Workers.h +++ b/src/beast/beast/module/core/thread/Workers.h @@ -56,7 +56,8 @@ public: */ explicit Workers (Callback& callback, String const& threadNames = "Worker", - int numberOfThreads = std::thread::hardware_concurrency()); + int numberOfThreads = + static_cast(std::thread::hardware_concurrency())); ~Workers (); diff --git a/src/ripple/core/impl/JobQueue.cpp b/src/ripple/core/impl/JobQueue.cpp index 50d3cd44c..f4601f128 100644 --- a/src/ripple/core/impl/JobQueue.cpp +++ b/src/ripple/core/impl/JobQueue.cpp @@ -226,18 +226,8 @@ public: } else if (c == 0) { - c = std::thread::hardware_concurrency(); - - // VFALCO NOTE According to boost, hardware_concurrency cannot return - // negative numbers/ - // - if (c < 0) - c = 2; // VFALCO NOTE Why 2? - - if (c > 4) // I/O will bottleneck - c = 4; - - c += 2; + c = static_cast(std::thread::hardware_concurrency()); + c = 2 + std::min (c, 4); // I/O will bottleneck m_journal.info << "Auto-tuning to " << c << " validation/transaction/proposal threads";