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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 if (max_blocking_tasks_after_shutdown_ <= 0) { | 586 if (max_blocking_tasks_after_shutdown_ <= 0) { |
587 DLOG(WARNING) << "BLOCK_SHUTDOWN task disallowed"; | 587 DLOG(WARNING) << "BLOCK_SHUTDOWN task disallowed"; |
588 return false; | 588 return false; |
589 } | 589 } |
590 max_blocking_tasks_after_shutdown_ -= 1; | 590 max_blocking_tasks_after_shutdown_ -= 1; |
591 } | 591 } |
592 | 592 |
593 // The trace_id is used for identifying the task in about:tracing. | 593 // The trace_id is used for identifying the task in about:tracing. |
594 sequenced.trace_id = trace_id_++; | 594 sequenced.trace_id = trace_id_++; |
595 | 595 |
596 TRACE_EVENT_FLOW_BEGIN0("task", "SequencedWorkerPool::PostTask", | 596 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
| 597 "SequencedWorkerPool::PostTask", |
597 TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this)))); | 598 TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this)))); |
598 | 599 |
599 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber(); | 600 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber(); |
600 | 601 |
601 // Now that we have the lock, apply the named token rules. | 602 // Now that we have the lock, apply the named token rules. |
602 if (optional_token_name) | 603 if (optional_token_name) |
603 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name); | 604 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name); |
604 | 605 |
605 pending_tasks_.insert(sequenced); | 606 pending_tasks_.insert(sequenced); |
606 if (shutdown_behavior == BLOCK_SHUTDOWN) | 607 if (shutdown_behavior == BLOCK_SHUTDOWN) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 | 720 |
720 HandleCleanup(); | 721 HandleCleanup(); |
721 | 722 |
722 // See GetWork for what delete_these_outside_lock is doing. | 723 // See GetWork for what delete_these_outside_lock is doing. |
723 SequencedTask task; | 724 SequencedTask task; |
724 TimeDelta wait_time; | 725 TimeDelta wait_time; |
725 std::vector<Closure> delete_these_outside_lock; | 726 std::vector<Closure> delete_these_outside_lock; |
726 GetWorkStatus status = | 727 GetWorkStatus status = |
727 GetWork(&task, &wait_time, &delete_these_outside_lock); | 728 GetWork(&task, &wait_time, &delete_these_outside_lock); |
728 if (status == GET_WORK_FOUND) { | 729 if (status == GET_WORK_FOUND) { |
729 TRACE_EVENT_FLOW_END0("task", "SequencedWorkerPool::PostTask", | 730 TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), |
| 731 "SequencedWorkerPool::PostTask", |
730 TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this)))); | 732 TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this)))); |
731 TRACE_EVENT2("task", "SequencedWorkerPool::ThreadLoop", | 733 TRACE_EVENT2("toplevel", "SequencedWorkerPool::ThreadLoop", |
732 "src_file", task.posted_from.file_name(), | 734 "src_file", task.posted_from.file_name(), |
733 "src_func", task.posted_from.function_name()); | 735 "src_func", task.posted_from.function_name()); |
734 int new_thread_id = WillRunWorkerTask(task); | 736 int new_thread_id = WillRunWorkerTask(task); |
735 { | 737 { |
736 AutoUnlock unlock(lock_); | 738 AutoUnlock unlock(lock_); |
737 // There may be more work available, so wake up another | 739 // There may be more work available, so wake up another |
738 // worker thread. (Technically not required, since we | 740 // worker thread. (Technically not required, since we |
739 // already get a signal for each new task, but it doesn't | 741 // already get a signal for each new task, but it doesn't |
740 // hurt.) | 742 // hurt.) |
741 SignalHasWork(); | 743 SignalHasWork(); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1280 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
1279 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); | 1281 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); |
1280 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1282 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
1281 } | 1283 } |
1282 | 1284 |
1283 bool SequencedWorkerPool::IsShutdownInProgress() { | 1285 bool SequencedWorkerPool::IsShutdownInProgress() { |
1284 return inner_->IsShutdownInProgress(); | 1286 return inner_->IsShutdownInProgress(); |
1285 } | 1287 } |
1286 | 1288 |
1287 } // namespace base | 1289 } // namespace base |
OLD | NEW |