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

Side by Side Diff: base/threading/sequenced_worker_pool.cc

Issue 2346823002: Forward return value of PostTaskToTaskScheduler() to PostTask() in SequencedWorkerPool. (Closed)
Patch Set: Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 enum CleanupState { 375 enum CleanupState {
376 CLEANUP_REQUESTED, 376 CLEANUP_REQUESTED,
377 CLEANUP_STARTING, 377 CLEANUP_STARTING,
378 CLEANUP_RUNNING, 378 CLEANUP_RUNNING,
379 CLEANUP_FINISHING, 379 CLEANUP_FINISHING,
380 CLEANUP_DONE, 380 CLEANUP_DONE,
381 }; 381 };
382 382
383 // Helper used by PostTask() to complete the work when redirection is on. 383 // Helper used by PostTask() to complete the work when redirection is on.
384 // Returns true if the task may run at some point in the future and false if
385 // it will definitely not run.
384 // Coalesce upon resolution of http://crbug.com/622400. 386 // Coalesce upon resolution of http://crbug.com/622400.
385 void PostTaskToTaskScheduler(const SequencedTask& sequenced, 387 bool PostTaskToTaskScheduler(const SequencedTask& sequenced,
386 const TimeDelta& delay); 388 const TimeDelta& delay);
387 389
388 // Returns the TaskScheduler TaskRunner for the specified |sequence_token_id| 390 // Returns the TaskScheduler TaskRunner for the specified |sequence_token_id|
389 // and |traits|. 391 // and |traits|.
390 scoped_refptr<TaskRunner> GetTaskSchedulerTaskRunner( 392 scoped_refptr<TaskRunner> GetTaskSchedulerTaskRunner(
391 int sequence_token_id, 393 int sequence_token_id,
392 const TaskTraits& traits); 394 const TaskTraits& traits);
393 395
394 // Called from within the lock, this converts the given token name into a 396 // Called from within the lock, this converts the given token name into a
395 // token ID, creating a new one if necessary. 397 // token ID, creating a new one if necessary.
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 TRACE_EVENT_FLAG_FLOW_OUT); 726 TRACE_EVENT_FLAG_FLOW_OUT);
725 727
726 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber(); 728 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber();
727 729
728 // Now that we have the lock, apply the named token rules. 730 // Now that we have the lock, apply the named token rules.
729 if (optional_token_name) 731 if (optional_token_name)
730 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name); 732 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name);
731 733
732 if (subtle::NoBarrier_Load(&g_all_pools_state) == 734 if (subtle::NoBarrier_Load(&g_all_pools_state) ==
733 AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { 735 AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) {
734 PostTaskToTaskScheduler(sequenced, delay); 736 if (!PostTaskToTaskScheduler(sequenced, delay))
737 return false;
735 } else { 738 } else {
736 pending_tasks_.insert(sequenced); 739 pending_tasks_.insert(sequenced);
737 740
738 if (sequenced.shutdown_behavior == BLOCK_SHUTDOWN) 741 if (sequenced.shutdown_behavior == BLOCK_SHUTDOWN)
739 blocking_shutdown_pending_task_count_++; 742 blocking_shutdown_pending_task_count_++;
740 743
741 create_thread_id = PrepareToStartAdditionalThreadIfHelpful(); 744 create_thread_id = PrepareToStartAdditionalThreadIfHelpful();
742 } 745 }
743 } 746 }
744 747
(...skipping 18 matching lines...) Expand all
763 DCHECK_EQ(0, create_thread_id); 766 DCHECK_EQ(0, create_thread_id);
764 } else { 767 } else {
765 DCHECK(sequenced_task_runner_map_.empty()); 768 DCHECK(sequenced_task_runner_map_.empty());
766 } 769 }
767 } 770 }
768 #endif // DCHECK_IS_ON() 771 #endif // DCHECK_IS_ON()
769 772
770 return true; 773 return true;
771 } 774 }
772 775
773 void SequencedWorkerPool::Inner::PostTaskToTaskScheduler( 776 bool SequencedWorkerPool::Inner::PostTaskToTaskScheduler(
774 const SequencedTask& sequenced, 777 const SequencedTask& sequenced,
775 const TimeDelta& delay) { 778 const TimeDelta& delay) {
776 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER, 779 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER,
777 subtle::NoBarrier_Load(&g_all_pools_state)); 780 subtle::NoBarrier_Load(&g_all_pools_state));
778 781
779 lock_.AssertAcquired(); 782 lock_.AssertAcquired();
780 783
781 // Confirm that the TaskScheduler's shutdown behaviors use the same 784 // Confirm that the TaskScheduler's shutdown behaviors use the same
782 // underlying values as SequencedWorkerPool. 785 // underlying values as SequencedWorkerPool.
783 static_assert( 786 static_assert(
784 static_cast<int>(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) == 787 static_cast<int>(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) ==
785 static_cast<int>(CONTINUE_ON_SHUTDOWN), 788 static_cast<int>(CONTINUE_ON_SHUTDOWN),
786 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " 789 "TaskShutdownBehavior and WorkerShutdown enum mismatch for "
787 "CONTINUE_ON_SHUTDOWN."); 790 "CONTINUE_ON_SHUTDOWN.");
788 static_assert(static_cast<int>(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) == 791 static_assert(static_cast<int>(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) ==
789 static_cast<int>(SKIP_ON_SHUTDOWN), 792 static_cast<int>(SKIP_ON_SHUTDOWN),
790 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " 793 "TaskShutdownBehavior and WorkerShutdown enum mismatch for "
791 "SKIP_ON_SHUTDOWN."); 794 "SKIP_ON_SHUTDOWN.");
792 static_assert(static_cast<int>(TaskShutdownBehavior::BLOCK_SHUTDOWN) == 795 static_assert(static_cast<int>(TaskShutdownBehavior::BLOCK_SHUTDOWN) ==
793 static_cast<int>(BLOCK_SHUTDOWN), 796 static_cast<int>(BLOCK_SHUTDOWN),
794 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " 797 "TaskShutdownBehavior and WorkerShutdown enum mismatch for "
795 "BLOCK_SHUTDOWN."); 798 "BLOCK_SHUTDOWN.");
796 799
797 const TaskShutdownBehavior task_shutdown_behavior = 800 const TaskShutdownBehavior task_shutdown_behavior =
798 static_cast<TaskShutdownBehavior>(sequenced.shutdown_behavior); 801 static_cast<TaskShutdownBehavior>(sequenced.shutdown_behavior);
799 const TaskTraits traits = TaskTraits() 802 const TaskTraits traits = TaskTraits()
800 .WithFileIO() 803 .WithFileIO()
801 .WithPriority(task_priority_) 804 .WithPriority(task_priority_)
802 .WithShutdownBehavior(task_shutdown_behavior); 805 .WithShutdownBehavior(task_shutdown_behavior);
803 GetTaskSchedulerTaskRunner(sequenced.sequence_token_id, traits) 806 return GetTaskSchedulerTaskRunner(sequenced.sequence_token_id, traits)
804 ->PostDelayedTask(sequenced.posted_from, sequenced.task, delay); 807 ->PostDelayedTask(sequenced.posted_from, sequenced.task, delay);
805 } 808 }
806 809
807 scoped_refptr<TaskRunner> 810 scoped_refptr<TaskRunner>
808 SequencedWorkerPool::Inner::GetTaskSchedulerTaskRunner( 811 SequencedWorkerPool::Inner::GetTaskSchedulerTaskRunner(
809 int sequence_token_id, 812 int sequence_token_id,
810 const TaskTraits& traits) { 813 const TaskTraits& traits) {
811 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER, 814 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER,
812 subtle::NoBarrier_Load(&g_all_pools_state)); 815 subtle::NoBarrier_Load(&g_all_pools_state));
813 816
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1612 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1610 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1613 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1611 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1614 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1612 } 1615 }
1613 1616
1614 bool SequencedWorkerPool::IsShutdownInProgress() { 1617 bool SequencedWorkerPool::IsShutdownInProgress() {
1615 return inner_->IsShutdownInProgress(); 1618 return inner_->IsShutdownInProgress();
1616 } 1619 }
1617 1620
1618 } // namespace base 1621 } // 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