Chromium Code Reviews| Index: base/test/sequenced_task_runner_test_template.cc |
| =================================================================== |
| --- base/test/sequenced_task_runner_test_template.cc (revision 0) |
| +++ base/test/sequenced_task_runner_test_template.cc (revision 0) |
| @@ -0,0 +1,86 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/test/sequenced_task_runner_test_template.h" |
| + |
| +namespace base { |
| + |
| +namespace internal { |
| + |
| +SequencedTaskTracker::SequencedTaskTracker() : next_post_i_(0) { |
| +} |
| + |
| +SequencedTaskTracker::~SequencedTaskTracker() { |
| +} |
| + |
| +int SequencedTaskTracker::GetNextPostOrdinal() { |
| + return next_post_i_++; |
| +} |
| + |
| +void SequencedTaskTracker::TaskPosted(int i) { |
| + AutoLock lock(post_lock_); |
| + post_events_.push_back(i); |
| +} |
| + |
| +void SequencedTaskTracker::TaskStarted(int i) { |
| + AutoLock lock(start_lock_); |
| + start_events_.push_back(i); |
| +} |
| + |
| +void SequencedTaskTracker::TaskEnded(int i) { |
| + AutoLock lock(end_lock_); |
| + end_events_.push_back(i); |
| +} |
| + |
| +const std::vector<int>& |
| +SequencedTaskTracker::GetPostOrder() const { |
| + return post_events_; |
| +} |
| + |
| +const std::vector<int>& |
| +SequencedTaskTracker::GetStartOrder() const { |
| + return start_events_; |
| +} |
| + |
| +const std::vector<int>& |
| +SequencedTaskTracker::GetEndOrder() const { |
| + return end_events_; |
| +} |
| + |
| +void SequencedTaskTracker::FastTask(int i) { |
| + TaskStarted(i); |
| + base::PlatformThread::YieldCurrentThread(); |
| + TaskEnded(i); |
| +} |
| + |
| +void SequencedTaskTracker::SlowTask(int i) { |
| + TaskStarted(i); |
| + base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| + TaskEnded(i); |
| +} |
| + |
| +void SequencedTaskTracker::PostFastNonNestableFromSlowNonNestable( |
| + scoped_refptr<SequencedTaskRunner> task_runner, |
| + const int i, |
| + const int child_count) { |
| + |
| + TaskStarted(i); |
| + |
| + for (int j = 0; j < child_count; ++j) { |
| + base::PlatformThread::YieldCurrentThread(); |
| + AutoLock post_lock(post_lock_); |
| + const int child_i = GetNextPostOrdinal(); |
| + Closure task = Bind(&SequencedTaskTracker::FastTask, |
| + this, |
| + child_i); |
| + post_events_.push_back(child_i); |
| + task_runner->PostNonNestableTask(FROM_HERE, task); |
|
Francois
2012/03/18 16:28:29
The loop body is messy, but I want to hear your co
|
| + } |
| + |
| + TaskEnded(i); |
| +} |
| + |
| +} // namespace internal |
| + |
| +} // namespace base |
| Property changes on: base/test/sequenced_task_runner_test_template.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |