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

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

Issue 2917433002: Followup to https://codereview.chromium.org/2902753003/ (Closed)
Patch Set: Created 3 years, 6 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/scheduler_single_thread_task_runner_manager.h ('k') | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/scheduler_single_thread_task_runner_manager.h" 5 #include "base/task_scheduler/scheduler_single_thread_task_runner_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 const TaskTraits traits_; 323 const TaskTraits traits_;
324 SchedulerWorker* const worker_; 324 SchedulerWorker* const worker_;
325 const SingleThreadTaskRunnerThreadMode thread_mode_; 325 const SingleThreadTaskRunnerThreadMode thread_mode_;
326 326
327 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunner); 327 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunner);
328 }; 328 };
329 329
330 SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunnerManager( 330 SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunnerManager(
331 TaskTracker* task_tracker, 331 TaskTracker* task_tracker,
332 DelayedTaskManager* delayed_task_manager) 332 DelayedTaskManager* delayed_task_manager)
333 : task_tracker_(task_tracker), 333 : task_tracker_(task_tracker), delayed_task_manager_(delayed_task_manager) {
334 delayed_task_manager_(delayed_task_manager),
335 shared_scheduler_workers_ {}
336 #if defined(OS_WIN)
337 ,
338 shared_com_scheduler_workers_ {}
339 #endif // defined(OS_WIN)
340 {
341 DCHECK(task_tracker_); 334 DCHECK(task_tracker_);
342 DCHECK(delayed_task_manager_); 335 DCHECK(delayed_task_manager_);
343 static_assert(
344 arraysize(shared_scheduler_workers_) == ENVIRONMENT_COUNT,
345 "The size of |shared_scheduler_workers_| must match ENVIRONMENT_COUNT");
346 #if defined(OS_WIN) 336 #if defined(OS_WIN)
347 static_assert(arraysize(shared_com_scheduler_workers_) == 337 static_assert(arraysize(shared_com_scheduler_workers_) ==
348 arraysize(shared_scheduler_workers_), 338 arraysize(shared_scheduler_workers_),
349 "The size of |shared_com_scheduler_workers_| must match " 339 "The size of |shared_com_scheduler_workers_| must match "
350 "|shared_scheduler_workers_|"); 340 "|shared_scheduler_workers_|");
351 #endif // defined(OS_WIN) 341 #endif // defined(OS_WIN)
352 } 342 }
353 343
354 SchedulerSingleThreadTaskRunnerManager:: 344 SchedulerSingleThreadTaskRunnerManager::
355 ~SchedulerSingleThreadTaskRunnerManager() { 345 ~SchedulerSingleThreadTaskRunnerManager() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 template <typename DelegateType> 410 template <typename DelegateType>
421 scoped_refptr< 411 scoped_refptr<
422 SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunner> 412 SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunner>
423 SchedulerSingleThreadTaskRunnerManager::CreateTaskRunnerWithTraitsImpl( 413 SchedulerSingleThreadTaskRunnerManager::CreateTaskRunnerWithTraitsImpl(
424 const std::string& name, 414 const std::string& name,
425 const TaskTraits& traits, 415 const TaskTraits& traits,
426 SingleThreadTaskRunnerThreadMode thread_mode) { 416 SingleThreadTaskRunnerThreadMode thread_mode) {
427 DCHECK(thread_mode != SingleThreadTaskRunnerThreadMode::SHARED || 417 DCHECK(thread_mode != SingleThreadTaskRunnerThreadMode::SHARED ||
428 !traits.with_base_sync_primitives()) 418 !traits.with_base_sync_primitives())
429 << "Using WithBaseSyncPrimitives() on a shared SingleThreadTaskRunner " 419 << "Using WithBaseSyncPrimitives() on a shared SingleThreadTaskRunner "
430 "may cause deadlocks. Either reevaluate your usage pattern or use " 420 "may cause deadlocks. Either reevaluate your usage (e.g. use "
421 "SequencedTaskRunner) or use "
431 "SingleThreadTaskRunnerThreadMode::DEDICATED."; 422 "SingleThreadTaskRunnerThreadMode::DEDICATED.";
432 // To simplify the code, |dedicated_worker| is a local only variable that 423 // To simplify the code, |dedicated_worker| is a local only variable that
433 // allows the code to treat both the DEDICATED and SHARED cases similarly for 424 // allows the code to treat both the DEDICATED and SHARED cases similarly for
434 // SingleThreadTaskRunnerThreadMode. In DEDICATED, the scoped_refptr is backed 425 // SingleThreadTaskRunnerThreadMode. In DEDICATED, the scoped_refptr is backed
435 // by a local variable and in SHARED, the scoped_refptr is backed by a member 426 // by a local variable and in SHARED, the scoped_refptr is backed by a member
436 // variable. 427 // variable.
437 SchedulerWorker* dedicated_worker = nullptr; 428 SchedulerWorker* dedicated_worker = nullptr;
438 SchedulerWorker*& worker = 429 SchedulerWorker*& worker =
439 thread_mode == SingleThreadTaskRunnerThreadMode::DEDICATED 430 thread_mode == SingleThreadTaskRunnerThreadMode::DEDICATED
440 ? dedicated_worker 431 ? dedicated_worker
(...skipping 12 matching lines...) Expand all
453 worker = CreateAndRegisterSchedulerWorker<DelegateType>( 444 worker = CreateAndRegisterSchedulerWorker<DelegateType>(
454 processed_name, environment_params.priority_hint); 445 processed_name, environment_params.priority_hint);
455 new_worker = true; 446 new_worker = true;
456 } 447 }
457 started = started_; 448 started = started_;
458 } 449 }
459 450
460 if (new_worker && started) 451 if (new_worker && started)
461 worker->Start(); 452 worker->Start();
462 453
463 return new SchedulerSingleThreadTaskRunner(this, traits, worker, thread_mode); 454 return MakeRefCounted<SchedulerSingleThreadTaskRunner>(this, traits, worker,
455 thread_mode);
464 } 456 }
465 457
466 void SchedulerSingleThreadTaskRunnerManager::JoinForTesting() { 458 void SchedulerSingleThreadTaskRunnerManager::JoinForTesting() {
467 ReleaseSharedSchedulerWorkers(); 459 ReleaseSharedSchedulerWorkers();
468 460
469 decltype(workers_) local_workers; 461 decltype(workers_) local_workers;
470 { 462 {
471 AutoSchedulerLock auto_lock(lock_); 463 AutoSchedulerLock auto_lock(lock_);
472 local_workers = std::move(workers_); 464 local_workers = std::move(workers_);
473 } 465 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 554
563 void SchedulerSingleThreadTaskRunnerManager::ReleaseSharedSchedulerWorkers() { 555 void SchedulerSingleThreadTaskRunnerManager::ReleaseSharedSchedulerWorkers() {
564 decltype(shared_scheduler_workers_) local_shared_scheduler_workers; 556 decltype(shared_scheduler_workers_) local_shared_scheduler_workers;
565 #if defined(OS_WIN) 557 #if defined(OS_WIN)
566 decltype(shared_com_scheduler_workers_) local_shared_com_scheduler_workers; 558 decltype(shared_com_scheduler_workers_) local_shared_com_scheduler_workers;
567 #endif 559 #endif
568 { 560 {
569 AutoSchedulerLock auto_lock(lock_); 561 AutoSchedulerLock auto_lock(lock_);
570 for (size_t i = 0; i < arraysize(shared_scheduler_workers_); ++i) { 562 for (size_t i = 0; i < arraysize(shared_scheduler_workers_); ++i) {
571 local_shared_scheduler_workers[i] = shared_scheduler_workers_[i]; 563 local_shared_scheduler_workers[i] = shared_scheduler_workers_[i];
564 shared_scheduler_workers_[i] = nullptr;
572 #if defined(OS_WIN) 565 #if defined(OS_WIN)
573 local_shared_com_scheduler_workers[i] = shared_com_scheduler_workers_[i]; 566 local_shared_com_scheduler_workers[i] = shared_com_scheduler_workers_[i];
567 shared_com_scheduler_workers_[i] = nullptr;
574 #endif 568 #endif
575 } 569 }
576 } 570 }
577 571
578 for (size_t i = 0; i < arraysize(local_shared_scheduler_workers); ++i) { 572 for (size_t i = 0; i < arraysize(local_shared_scheduler_workers); ++i) {
579 if (local_shared_scheduler_workers[i]) 573 if (local_shared_scheduler_workers[i])
580 UnregisterSchedulerWorker(local_shared_scheduler_workers[i]); 574 UnregisterSchedulerWorker(local_shared_scheduler_workers[i]);
581 #if defined(OS_WIN) 575 #if defined(OS_WIN)
582 if (local_shared_com_scheduler_workers[i]) 576 if (local_shared_com_scheduler_workers[i])
583 UnregisterSchedulerWorker(local_shared_com_scheduler_workers[i]); 577 UnregisterSchedulerWorker(local_shared_com_scheduler_workers[i]);
584 #endif 578 #endif
585 } 579 }
586 } 580 }
587 581
588 } // namespace internal 582 } // namespace internal
589 } // namespace base 583 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_single_thread_task_runner_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698