Commit 123f3704 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[base] Mark TestTaskTracker's CVs as declare_only_used_while_idle()

This prevents TaskEnvironment::FastForwardBy() from instantiating
ScopedBlockingCalls and confusing internal //base tests.

It is also conceptually correct as we wouldn't want to replace
worker threads blocked on TestTaskTracker.

R=fdoray@chromium.org

Bug: 1064645
Change-Id: I304ccbf270177ddb1435aed81e52b26fe9b5a41b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2133049Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755926}
parent f0928e43
...@@ -136,7 +136,7 @@ class TaskEnvironment::TestTaskTracker ...@@ -136,7 +136,7 @@ class TaskEnvironment::TestTaskTracker
ConditionVariable can_run_tasks_cv_ GUARDED_BY(lock_); ConditionVariable can_run_tasks_cv_ GUARDED_BY(lock_);
// Signaled when a task is completed. // Signaled when a task is completed.
ConditionVariable task_completed_ GUARDED_BY(lock_); ConditionVariable task_completed_cv_ GUARDED_BY(lock_);
// Number of tasks that are currently running. // Number of tasks that are currently running.
int num_tasks_running_ GUARDED_BY(lock_) = 0; int num_tasks_running_ GUARDED_BY(lock_) = 0;
...@@ -731,7 +731,12 @@ void TaskEnvironment::RemoveDestructionObserver(DestructionObserver* observer) { ...@@ -731,7 +731,12 @@ void TaskEnvironment::RemoveDestructionObserver(DestructionObserver* observer) {
TaskEnvironment::TestTaskTracker::TestTaskTracker() TaskEnvironment::TestTaskTracker::TestTaskTracker()
: internal::ThreadPoolImpl::TaskTrackerImpl(std::string()), : internal::ThreadPoolImpl::TaskTrackerImpl(std::string()),
can_run_tasks_cv_(&lock_), can_run_tasks_cv_(&lock_),
task_completed_(&lock_) {} task_completed_cv_(&lock_) {
// Consider threads blocked on these as idle (avoids instantiating
// ScopedBlockingCalls and confusing some //base internals tests).
can_run_tasks_cv_.declare_only_used_while_idle();
task_completed_cv_.declare_only_used_while_idle();
}
bool TaskEnvironment::TestTaskTracker::AllowRunTasks() { bool TaskEnvironment::TestTaskTracker::AllowRunTasks() {
AutoLock auto_lock(lock_); AutoLock auto_lock(lock_);
...@@ -754,7 +759,7 @@ bool TaskEnvironment::TestTaskTracker::DisallowRunTasks() { ...@@ -754,7 +759,7 @@ bool TaskEnvironment::TestTaskTracker::DisallowRunTasks() {
// Attempt to wait a bit so that the caller doesn't busy-loop with the same // Attempt to wait a bit so that the caller doesn't busy-loop with the same
// set of pending work. A short wait is required to avoid deadlock // set of pending work. A short wait is required to avoid deadlock
// scenarios. See DisallowRunTasks()'s declaration for more details. // scenarios. See DisallowRunTasks()'s declaration for more details.
task_completed_.TimedWait(TimeDelta::FromMilliseconds(1)); task_completed_cv_.TimedWait(TimeDelta::FromMilliseconds(1));
return false; return false;
} }
...@@ -800,7 +805,7 @@ void TaskEnvironment::TestTaskTracker::RunTask(internal::Task task, ...@@ -800,7 +805,7 @@ void TaskEnvironment::TestTaskTracker::RunTask(internal::Task task,
--num_tasks_running_; --num_tasks_running_;
task_completed_.Broadcast(); task_completed_cv_.Broadcast();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment