1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/task/thread_pool/initialization_util.h" 6 7 #include <algorithm> 8 #include <cmath> 9 10 #include "base/numerics/clamped_math.h" 11 #include "base/system/sys_info.h" 12 13 namespace base { 14 RecommendedMaxNumberOfThreadsInThreadGroup(size_t min,size_t max,double cores_multiplier,int offset)15size_t RecommendedMaxNumberOfThreadsInThreadGroup(size_t min, 16 size_t max, 17 double cores_multiplier, 18 int offset) { 19 const auto num_of_cores = static_cast<size_t>(SysInfo::NumberOfProcessors()); 20 const size_t threads = ClampAdd<size_t>( 21 std::ceil<size_t>(num_of_cores * cores_multiplier), offset); 22 return std::clamp(threads, min, max); 23 } 24 25 } // namespace base 26