xref: /aosp_15_r20/external/cronet/base/task/thread_pool/initialization_util.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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/system/sys_info.h"
11 
12 namespace base {
13 
RecommendedMaxNumberOfThreadsInThreadGroup(size_t min,size_t max,double cores_multiplier,size_t offset)14 size_t RecommendedMaxNumberOfThreadsInThreadGroup(size_t min,
15                                                   size_t max,
16                                                   double cores_multiplier,
17                                                   size_t offset) {
18   const auto num_of_cores = static_cast<size_t>(SysInfo::NumberOfProcessors());
19   const size_t threads =
20       std::ceil<size_t>(num_of_cores * cores_multiplier) + offset;
21   return std::clamp(threads, min, max);
22 }
23 
24 }  // namespace base
25