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

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

Issue 1239593002: Implement a new flow event API that allows binding flow events and regular events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement binding flow events to slices for PostTasks. Created 5 years, 5 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
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 <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 if (max_blocking_tasks_after_shutdown_ <= 0) { 612 if (max_blocking_tasks_after_shutdown_ <= 0) {
613 DLOG(WARNING) << "BLOCK_SHUTDOWN task disallowed"; 613 DLOG(WARNING) << "BLOCK_SHUTDOWN task disallowed";
614 return false; 614 return false;
615 } 615 }
616 max_blocking_tasks_after_shutdown_ -= 1; 616 max_blocking_tasks_after_shutdown_ -= 1;
617 } 617 }
618 618
619 // The trace_id is used for identifying the task in about:tracing. 619 // The trace_id is used for identifying the task in about:tracing.
620 sequenced.trace_id = trace_id_++; 620 sequenced.trace_id = trace_id_++;
621 621
622 TRACE_EVENT_WITH_FLOW0(
623 "toplevel", "SequencedWorkerPool::Inner::PostTask",
624 TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this))),
625 TRACE_EVENT_FLAG_FLOW_OUT);
622 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), 626 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
623 "SequencedWorkerPool::PostTask", 627 "SequencedWorkerPool::PostTask",
624 TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this)))); 628 TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this))));
625 629
626 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber(); 630 sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber();
627 631
628 // Now that we have the lock, apply the named token rules. 632 // Now that we have the lock, apply the named token rules.
629 if (optional_token_name) 633 if (optional_token_name)
630 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name); 634 sequenced.sequence_token_id = LockedGetNamedTokenID(*optional_token_name);
631 635
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 751
748 HandleCleanup(); 752 HandleCleanup();
749 753
750 // See GetWork for what delete_these_outside_lock is doing. 754 // See GetWork for what delete_these_outside_lock is doing.
751 SequencedTask task; 755 SequencedTask task;
752 TimeDelta wait_time; 756 TimeDelta wait_time;
753 std::vector<Closure> delete_these_outside_lock; 757 std::vector<Closure> delete_these_outside_lock;
754 GetWorkStatus status = 758 GetWorkStatus status =
755 GetWork(&task, &wait_time, &delete_these_outside_lock); 759 GetWork(&task, &wait_time, &delete_these_outside_lock);
756 if (status == GET_WORK_FOUND) { 760 if (status == GET_WORK_FOUND) {
761 TRACE_EVENT_WITH_FLOW2(
762 "toplevel", "SequencedWorkerPool::ThreadLoop",
763 TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this))),
764 TRACE_EVENT_FLAG_FLOW_IN, "src_file", task.posted_from.file_name(),
765 "src_func", task.posted_from.function_name());
757 TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), 766 TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
758 "SequencedWorkerPool::PostTask", 767 "SequencedWorkerPool::PostTask",
759 TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this)))); 768 TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this))));
760 TRACE_EVENT2("toplevel", "SequencedWorkerPool::ThreadLoop",
761 "src_file", task.posted_from.file_name(),
762 "src_func", task.posted_from.function_name());
763 int new_thread_id = WillRunWorkerTask(task); 769 int new_thread_id = WillRunWorkerTask(task);
764 { 770 {
765 AutoUnlock unlock(lock_); 771 AutoUnlock unlock(lock_);
766 // There may be more work available, so wake up another 772 // There may be more work available, so wake up another
767 // worker thread. (Technically not required, since we 773 // worker thread. (Technically not required, since we
768 // already get a signal for each new task, but it doesn't 774 // already get a signal for each new task, but it doesn't
769 // hurt.) 775 // hurt.)
770 SignalHasWork(); 776 SignalHasWork();
771 delete_these_outside_lock.clear(); 777 delete_these_outside_lock.clear();
772 778
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1304 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1299 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1305 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1300 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1306 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1301 } 1307 }
1302 1308
1303 bool SequencedWorkerPool::IsShutdownInProgress() { 1309 bool SequencedWorkerPool::IsShutdownInProgress() {
1304 return inner_->IsShutdownInProgress(); 1310 return inner_->IsShutdownInProgress();
1305 } 1311 }
1306 1312
1307 } // namespace base 1313 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698