Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: base/task_scheduler/task_scheduler.cc

Issue 2791423003: Initialize TaskScheduler with InitParams in CreateAndSetSimpleTaskScheduler(). (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/task_scheduler.h" 5 #include "base/task_scheduler/task_scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/sys_info.h" 11 #include "base/sys_info.h"
12 #include "base/task_scheduler/initialization_util.h"
12 #include "base/task_scheduler/scheduler_worker_pool_params.h" 13 #include "base/task_scheduler/scheduler_worker_pool_params.h"
13 #include "base/task_scheduler/task_scheduler_impl.h" 14 #include "base/task_scheduler/task_scheduler_impl.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 namespace { 20 namespace {
20 21
21 // |g_task_scheduler| is intentionally leaked on shutdown. 22 // |g_task_scheduler| is intentionally leaked on shutdown.
(...skipping 11 matching lines...) Expand all
33 background_blocking_worker_pool_params_in), 34 background_blocking_worker_pool_params_in),
34 foreground_worker_pool_params(foreground_worker_pool_params_in), 35 foreground_worker_pool_params(foreground_worker_pool_params_in),
35 foreground_blocking_worker_pool_params( 36 foreground_blocking_worker_pool_params(
36 foreground_blocking_worker_pool_params_in) {} 37 foreground_blocking_worker_pool_params_in) {}
37 38
38 TaskScheduler::InitParams::~InitParams() = default; 39 TaskScheduler::InitParams::~InitParams() = default;
39 40
40 #if !defined(OS_NACL) 41 #if !defined(OS_NACL)
41 // static 42 // static
42 void TaskScheduler::CreateAndSetSimpleTaskScheduler(const std::string& name) { 43 void TaskScheduler::CreateAndSetSimpleTaskScheduler(const std::string& name) {
43 constexpr int kMinNumThreads = 1; 44 using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy;
44 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector; 45
45 worker_pool_params_vector.emplace_back( 46 constexpr TimeDelta kSuggestedReclaimTime = TimeDelta::FromSeconds(30);
46 name, ThreadPriority::NORMAL, 47 constexpr int kMaxNumBackgroundThreads = 1;
47 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, 48 constexpr int kMaxNumBackgroundBlockingThreads = 2;
48 std::max(kMinNumThreads, SysInfo::NumberOfProcessors()), 49 constexpr int kMaxNumForegroundThreadsLowerBound = 2;
49 TimeDelta::FromSeconds(30)); 50 constexpr int kMaxNumForegroundThreadsUpperBound = 32;
51 constexpr double kMaxNumForegroundThreadsCoresMultiplier = 1;
52 constexpr int kMaxNumForegroundThreadsOffset = 0;
53 constexpr int kMaxNumForegroundBlockingThreadsLowerBound = 2;
54 constexpr int kMaxNumForegroundBlockingThreadsUpperBound = 64;
gab 2017/04/04 20:48:13 Why 32 and 64? Seems very high for a "simple" task
fdoray 2017/04/05 13:01:28 My thinking was that someone instantiating a simpl
robliao 2017/04/05 23:06:56 An alternative way to go about this is to adjust u
55 constexpr double kMaxNumForegroundBlockingThreadsCoresMultiplier = 2;
gab 2017/04/06 15:14:52 This isn't a MaxNum, it's a multiplier only, right
56 constexpr int kMaxNumForegroundBlockingThreadsOffset = 0;
57
50 CreateAndSetDefaultTaskScheduler( 58 CreateAndSetDefaultTaskScheduler(
51 worker_pool_params_vector, 59 name, {{StandbyThreadPolicy::LAZY, kMaxNumBackgroundThreads,
52 Bind([](const TaskTraits&) -> size_t { return 0; })); 60 kSuggestedReclaimTime},
61 {StandbyThreadPolicy::LAZY, kMaxNumBackgroundBlockingThreads,
62 kSuggestedReclaimTime},
63 {StandbyThreadPolicy::LAZY,
64 RecommendedMaxNumberOfThreadsInPool(
65 kMaxNumForegroundThreadsLowerBound,
66 kMaxNumForegroundThreadsUpperBound,
67 kMaxNumForegroundThreadsCoresMultiplier,
68 kMaxNumForegroundThreadsOffset),
69 kSuggestedReclaimTime},
70 {StandbyThreadPolicy::LAZY,
71 RecommendedMaxNumberOfThreadsInPool(
72 kMaxNumForegroundBlockingThreadsLowerBound,
73 kMaxNumForegroundBlockingThreadsUpperBound,
74 kMaxNumForegroundBlockingThreadsCoresMultiplier,
75 kMaxNumForegroundBlockingThreadsOffset),
76 kSuggestedReclaimTime}});
53 } 77 }
54 #endif // !defined(OS_NACL) 78 #endif // !defined(OS_NACL)
55 79
56 // static 80 // static
57 void TaskScheduler::CreateAndSetDefaultTaskScheduler( 81 void TaskScheduler::CreateAndSetDefaultTaskScheduler(
58 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, 82 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
59 const WorkerPoolIndexForTraitsCallback& 83 const WorkerPoolIndexForTraitsCallback&
60 worker_pool_index_for_traits_callback) { 84 worker_pool_index_for_traits_callback) {
61 SetInstance(internal::TaskSchedulerImpl::Create( 85 SetInstance(internal::TaskSchedulerImpl::Create(
62 worker_pool_params_vector, worker_pool_index_for_traits_callback)); 86 worker_pool_params_vector, worker_pool_index_for_traits_callback));
(...skipping 10 matching lines...) Expand all
73 delete g_task_scheduler; 97 delete g_task_scheduler;
74 g_task_scheduler = task_scheduler.release(); 98 g_task_scheduler = task_scheduler.release();
75 } 99 }
76 100
77 // static 101 // static
78 TaskScheduler* TaskScheduler::GetInstance() { 102 TaskScheduler* TaskScheduler::GetInstance() {
79 return g_task_scheduler; 103 return g_task_scheduler;
80 } 104 }
81 105
82 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698