OLD | NEW |
---|---|
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 <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 // but only worker threads are allowed to post tasks at that time, and | 796 // but only worker threads are allowed to post tasks at that time, and |
797 // the workers responsible for posting those tasks will be available | 797 // the workers responsible for posting those tasks will be available |
798 // to run them. Also, there may be some tasks stuck behind running | 798 // to run them. Also, there may be some tasks stuck behind running |
799 // ones with the same sequence token, but additional threads won't | 799 // ones with the same sequence token, but additional threads won't |
800 // help this case. | 800 // help this case. |
801 if (shutdown_called_ && blocking_shutdown_pending_task_count_ == 0) { | 801 if (shutdown_called_ && blocking_shutdown_pending_task_count_ == 0) { |
802 AutoUnlock unlock(lock_); | 802 AutoUnlock unlock(lock_); |
803 delete_these_outside_lock.clear(); | 803 delete_these_outside_lock.clear(); |
804 break; | 804 break; |
805 } | 805 } |
806 | |
807 // No work was found, but there are tasks that need deletion. The | |
808 // deletion must happen outside of the lock. Since the lock has been | |
brettw
2015/03/12 23:12:42
I don't follow this, maybe the comment needs to be
erikchen
2015/03/12 23:24:52
I broke the comment in two, moved the location of
| |
809 // released, the current state about whether there is more work is no | |
810 // longer valid, and needs to be recalculated by jumping to the top of | |
811 // the loop. | |
812 if (delete_these_outside_lock.size()) { | |
813 AutoUnlock unlock(lock_); | |
814 delete_these_outside_lock.clear(); | |
815 continue; | |
816 } | |
817 | |
806 waiting_thread_count_++; | 818 waiting_thread_count_++; |
807 | 819 |
808 switch (status) { | 820 switch (status) { |
809 case GET_WORK_NOT_FOUND: | 821 case GET_WORK_NOT_FOUND: |
810 has_work_cv_.Wait(); | 822 has_work_cv_.Wait(); |
811 break; | 823 break; |
812 case GET_WORK_WAIT: | 824 case GET_WORK_WAIT: |
813 has_work_cv_.TimedWait(wait_time); | 825 has_work_cv_.TimedWait(wait_time); |
814 break; | 826 break; |
815 default: | 827 default: |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1287 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
1276 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); | 1288 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); |
1277 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1289 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
1278 } | 1290 } |
1279 | 1291 |
1280 bool SequencedWorkerPool::IsShutdownInProgress() { | 1292 bool SequencedWorkerPool::IsShutdownInProgress() { |
1281 return inner_->IsShutdownInProgress(); | 1293 return inner_->IsShutdownInProgress(); |
1282 } | 1294 } |
1283 | 1295 |
1284 } // namespace base | 1296 } // namespace base |
OLD | NEW |