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

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

Issue 2729523006: Remove the |max_threads| argument from CreateAndSetSimpleTaskScheduler(). (Closed)
Patch Set: fix build error Created 3 years, 9 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 | « base/task_scheduler/task_scheduler.h ('k') | chrome/app/mash/mash_runner.cc » ('j') | 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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/sys_info.h"
9 #include "base/task_scheduler/scheduler_worker_pool_params.h" 12 #include "base/task_scheduler/scheduler_worker_pool_params.h"
10 #include "base/task_scheduler/task_scheduler_impl.h" 13 #include "base/task_scheduler/task_scheduler_impl.h"
11 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
12 #include "base/time/time.h" 15 #include "base/time/time.h"
13 16
14 namespace base { 17 namespace base {
15 18
16 namespace { 19 namespace {
17 20
18 // |g_task_scheduler| is intentionally leaked on shutdown. 21 // |g_task_scheduler| is intentionally leaked on shutdown.
19 TaskScheduler* g_task_scheduler = nullptr; 22 TaskScheduler* g_task_scheduler = nullptr;
20 23
21 } // namespace 24 } // namespace
22 25
26 #if !defined(OS_NACL)
23 // static 27 // static
24 void TaskScheduler::CreateAndSetSimpleTaskScheduler(int max_threads) { 28 void TaskScheduler::CreateAndSetSimpleTaskScheduler(const std::string& name) {
29 constexpr int kMinNumThreads = 1;
25 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector; 30 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector;
26 worker_pool_params_vector.emplace_back( 31 worker_pool_params_vector.emplace_back(
27 "Simple", ThreadPriority::NORMAL, 32 name, ThreadPriority::NORMAL,
28 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, max_threads, 33 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY,
34 std::max(kMinNumThreads, base::SysInfo::NumberOfProcessors()),
29 TimeDelta::FromSeconds(30)); 35 TimeDelta::FromSeconds(30));
30 CreateAndSetDefaultTaskScheduler( 36 CreateAndSetDefaultTaskScheduler(
31 worker_pool_params_vector, 37 worker_pool_params_vector,
32 Bind([](const TaskTraits&) -> size_t { return 0; })); 38 Bind([](const TaskTraits&) -> size_t { return 0; }));
33 } 39 }
40 #endif // !defined(OS_NACL)
34 41
35 // static 42 // static
36 void TaskScheduler::CreateAndSetDefaultTaskScheduler( 43 void TaskScheduler::CreateAndSetDefaultTaskScheduler(
37 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, 44 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
38 const WorkerPoolIndexForTraitsCallback& 45 const WorkerPoolIndexForTraitsCallback&
39 worker_pool_index_for_traits_callback) { 46 worker_pool_index_for_traits_callback) {
40 SetInstance(internal::TaskSchedulerImpl::Create( 47 SetInstance(internal::TaskSchedulerImpl::Create(
41 worker_pool_params_vector, worker_pool_index_for_traits_callback)); 48 worker_pool_params_vector, worker_pool_index_for_traits_callback));
42 } 49 }
43 50
44 // static 51 // static
45 void TaskScheduler::SetInstance(std::unique_ptr<TaskScheduler> task_scheduler) { 52 void TaskScheduler::SetInstance(std::unique_ptr<TaskScheduler> task_scheduler) {
46 delete g_task_scheduler; 53 delete g_task_scheduler;
47 g_task_scheduler = task_scheduler.release(); 54 g_task_scheduler = task_scheduler.release();
48 } 55 }
49 56
50 // static 57 // static
51 TaskScheduler* TaskScheduler::GetInstance() { 58 TaskScheduler* TaskScheduler::GetInstance() {
52 return g_task_scheduler; 59 return g_task_scheduler;
53 } 60 }
54 61
55 } // namespace base 62 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler.h ('k') | chrome/app/mash/mash_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698