Commit eed66837 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[ThreadPool]: Rename SequenceSortKey/TaskSourceSortKey.

Since it's used more generally for TaskSource. Coming CL will make use of
TaskSourceSortKey to schedule jobs more fairly.

Change-Id: I2084f56bf7082e39ed16a4afb19a9356f0390295
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377995Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803730}
parent ec6c569f
......@@ -683,14 +683,14 @@ component("base") {
"task/thread_pool/priority_queue.h",
"task/thread_pool/sequence.cc",
"task/thread_pool/sequence.h",
"task/thread_pool/sequence_sort_key.cc",
"task/thread_pool/sequence_sort_key.h",
"task/thread_pool/service_thread.cc",
"task/thread_pool/service_thread.h",
"task/thread_pool/task.cc",
"task/thread_pool/task.h",
"task/thread_pool/task_source.cc",
"task/thread_pool/task_source.h",
"task/thread_pool/task_source_sort_key.cc",
"task/thread_pool/task_source_sort_key.h",
"task/thread_pool/task_tracker.cc",
"task/thread_pool/task_tracker.h",
"task/thread_pool/thread_group.cc",
......@@ -2859,9 +2859,9 @@ test("base_unittests") {
"task/thread_pool/job_task_source_unittest.cc",
"task/thread_pool/pooled_single_thread_task_runner_manager_unittest.cc",
"task/thread_pool/priority_queue_unittest.cc",
"task/thread_pool/sequence_sort_key_unittest.cc",
"task/thread_pool/sequence_unittest.cc",
"task/thread_pool/service_thread_unittest.cc",
"task/thread_pool/task_source_sort_key_unittest.cc",
"task/thread_pool/task_tracker_unittest.cc",
"task/thread_pool/test_task_factory.cc",
"task/thread_pool/test_task_factory.h",
......
......@@ -343,8 +343,8 @@ bool JobTaskSource::DidProcessTask(TaskSource::Transaction* /*transaction*/) {
GetMaxConcurrency(state_before_sub.worker_count() - 1);
}
SequenceSortKey JobTaskSource::GetSortKey() const {
return SequenceSortKey(traits_.priority(), queue_time_);
TaskSourceSortKey JobTaskSource::GetSortKey() const {
return TaskSourceSortKey(traits_.priority(), queue_time_);
}
Task JobTaskSource::Clear(TaskSource::Transaction* transaction) {
......
......@@ -18,9 +18,9 @@
#include "base/task/common/checked_lock.h"
#include "base/task/post_job.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/task_source_sort_key.h"
namespace base {
namespace internal {
......@@ -182,7 +182,7 @@ class BASE_EXPORT JobTaskSource : public TaskSource {
Task TakeTask(TaskSource::Transaction* transaction) override;
Task Clear(TaskSource::Transaction* transaction) override;
bool DidProcessTask(TaskSource::Transaction* transaction) override;
SequenceSortKey GetSortKey() const override;
TaskSourceSortKey GetSortKey() const override;
// Synchronizes access to workers state.
mutable CheckedLock worker_lock_{UniversalSuccessor()};
......
......@@ -13,7 +13,7 @@
namespace base {
namespace internal {
// A class combining a TaskSource and the SequenceSortKey that determines its
// A class combining a TaskSource and the TaskSourceSortKey that determines its
// position in a PriorityQueue. Instances are only mutable via
// take_task_source() which can only be called once and renders its instance
// invalid after the call.
......@@ -21,7 +21,7 @@ class PriorityQueue::TaskSourceAndSortKey {
public:
TaskSourceAndSortKey() = default;
TaskSourceAndSortKey(RegisteredTaskSource task_source,
const SequenceSortKey& sort_key)
const TaskSourceSortKey& sort_key)
: task_source_(std::move(task_source)), sort_key_(sort_key) {
DCHECK(task_source_);
}
......@@ -73,11 +73,11 @@ class PriorityQueue::TaskSourceAndSortKey {
const RegisteredTaskSource& task_source() const { return task_source_; }
RegisteredTaskSource& task_source() { return task_source_; }
const SequenceSortKey& sort_key() const { return sort_key_; }
const TaskSourceSortKey& sort_key() const { return sort_key_; }
private:
RegisteredTaskSource task_source_;
SequenceSortKey sort_key_;
TaskSourceSortKey sort_key_;
DISALLOW_COPY_AND_ASSIGN(TaskSourceAndSortKey);
};
......@@ -99,14 +99,15 @@ PriorityQueue& PriorityQueue::operator=(PriorityQueue&& other) = default;
void PriorityQueue::Push(
TransactionWithRegisteredTaskSource transaction_with_task_source) {
auto sequence_sort_key =
auto task_source_sort_key =
transaction_with_task_source.transaction.GetSortKey();
container_.insert(TaskSourceAndSortKey(
std::move(transaction_with_task_source.task_source), sequence_sort_key));
IncrementNumTaskSourcesForPriority(sequence_sort_key.priority());
container_.insert(
TaskSourceAndSortKey(std::move(transaction_with_task_source.task_source),
task_source_sort_key));
IncrementNumTaskSourcesForPriority(task_source_sort_key.priority());
}
const SequenceSortKey& PriorityQueue::PeekSortKey() const {
const TaskSourceSortKey& PriorityQueue::PeekSortKey() const {
DCHECK(!IsEmpty());
return container_.Min().sort_key();
}
......
......@@ -12,8 +12,8 @@
#include "base/memory/ref_counted.h"
#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/task_source_sort_key.h"
namespace base {
namespace internal {
......@@ -27,14 +27,14 @@ class BASE_EXPORT PriorityQueue {
PriorityQueue& operator=(PriorityQueue&& other);
// Inserts |task_source| in the PriorityQueue with |sequence_sort_key|.
// Inserts |task_source| in the PriorityQueue with |task_source_sort_key|.
void Push(TransactionWithRegisteredTaskSource transaction_with_task_source);
// Returns a reference to the SequenceSortKey representing the priority of
// Returns a reference to the TaskSourceSortKey representing the priority of
// the highest pending task in this PriorityQueue. The reference becomes
// invalid the next time that this PriorityQueue is modified.
// Cannot be called on an empty PriorityQueue.
const SequenceSortKey& PeekSortKey() const;
const TaskSourceSortKey& PeekSortKey() const;
// Returns a reference to the highest priority TaskSource in this
// PriorityQueue. Cannot be called on an empty PriorityQueue. The returned
......@@ -73,8 +73,8 @@ class BASE_EXPORT PriorityQueue {
void EnableFlushTaskSourcesOnDestroyForTesting();
private:
// A class combining a TaskSource and the SequenceSortKey that determines its
// position in a PriorityQueue.
// A class combining a TaskSource and the TaskSourceSortKey that determines
// its position in a PriorityQueue.
class TaskSourceAndSortKey;
using ContainerType = IntrusiveHeap<TaskSourceAndSortKey>;
......
......@@ -59,19 +59,19 @@ class PriorityQueueWithSequencesTest : public testing::Test {
scoped_refptr<TaskSource> sequence_a =
MakeSequenceWithTraitsAndTask(TaskTraits(TaskPriority::USER_VISIBLE));
SequenceSortKey sort_key_a = sequence_a->BeginTransaction().GetSortKey();
TaskSourceSortKey sort_key_a = sequence_a->BeginTransaction().GetSortKey();
scoped_refptr<TaskSource> sequence_b =
MakeSequenceWithTraitsAndTask(TaskTraits(TaskPriority::USER_BLOCKING));
SequenceSortKey sort_key_b = sequence_b->BeginTransaction().GetSortKey();
TaskSourceSortKey sort_key_b = sequence_b->BeginTransaction().GetSortKey();
scoped_refptr<TaskSource> sequence_c =
MakeSequenceWithTraitsAndTask(TaskTraits(TaskPriority::USER_BLOCKING));
SequenceSortKey sort_key_c = sequence_c->BeginTransaction().GetSortKey();
TaskSourceSortKey sort_key_c = sequence_c->BeginTransaction().GetSortKey();
scoped_refptr<TaskSource> sequence_d =
MakeSequenceWithTraitsAndTask(TaskTraits(TaskPriority::BEST_EFFORT));
SequenceSortKey sort_key_d = sequence_d->BeginTransaction().GetSortKey();
TaskSourceSortKey sort_key_d = sequence_d->BeginTransaction().GetSortKey();
PriorityQueue pq;
};
......
......@@ -103,9 +103,9 @@ bool Sequence::DidProcessTask(TaskSource::Transaction* transaction) {
return true;
}
SequenceSortKey Sequence::GetSortKey() const {
TaskSourceSortKey Sequence::GetSortKey() const {
DCHECK(!queue_.empty());
return SequenceSortKey(traits_.priority(), queue_.front().queue_time);
return TaskSourceSortKey(traits_.priority(), queue_.front().queue_time);
}
Task Sequence::Clear(TaskSource::Transaction* transaction) {
......
......@@ -15,9 +15,9 @@
#include "base/sequence_token.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/pooled_parallel_task_runner.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/threading/sequence_local_storage_map.h"
namespace base {
......@@ -102,7 +102,7 @@ class BASE_EXPORT Sequence : public TaskSource {
Task TakeTask(TaskSource::Transaction* transaction) override;
Task Clear(TaskSource::Transaction* transaction) override;
bool DidProcessTask(TaskSource::Transaction* transaction) override;
SequenceSortKey GetSortKey() const override;
TaskSourceSortKey GetSortKey() const override;
// Releases reference to TaskRunner.
void ReleaseTaskRunner();
......
......@@ -127,7 +127,7 @@ TEST(ThreadPoolSequenceTest, GetSortKeyBestEffort) {
best_effort_sequence_transaction.PushTask(std::move(best_effort_task));
// Get the sort key.
const SequenceSortKey best_effort_sort_key =
const TaskSourceSortKey best_effort_sort_key =
best_effort_sequence_transaction.GetSortKey();
// Take the task from the sequence, so that its sequenced time is available
......@@ -161,7 +161,7 @@ TEST(ThreadPoolSequenceTest, GetSortKeyForeground) {
foreground_sequence_transaction.PushTask(std::move(foreground_task));
// Get the sort key.
const SequenceSortKey foreground_sort_key =
const TaskSourceSortKey foreground_sort_key =
foreground_sequence_transaction.GetSortKey();
// Take the task from the sequence, so that its sequenced time is available
......
......@@ -32,7 +32,7 @@ TaskSource::Transaction::~Transaction() {
}
}
SequenceSortKey TaskSource::Transaction::GetSortKey() const {
TaskSourceSortKey TaskSource::Transaction::GetSortKey() const {
return task_source_->GetSortKey();
}
......
......@@ -16,8 +16,8 @@
#include "base/task/common/checked_lock.h"
#include "base/task/common/intrusive_heap.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/threading/sequence_local_storage_map.h"
namespace base {
......@@ -105,9 +105,9 @@ class BASE_EXPORT TaskSource : public RefCountedThreadSafe<TaskSource> {
operator bool() const { return !!task_source_; }
// Returns a SequenceSortKey representing the priority of the TaskSource.
// Returns a TaskSourceSortKey representing the priority of the TaskSource.
// Cannot be called on an empty TaskSource.
SequenceSortKey GetSortKey() const;
TaskSourceSortKey GetSortKey() const;
// Sets TaskSource priority to |priority|.
void UpdatePriority(TaskPriority priority);
......@@ -193,7 +193,7 @@ class BASE_EXPORT TaskSource : public RefCountedThreadSafe<TaskSource> {
// are concurrently ready.
virtual Task Clear(TaskSource::Transaction* transaction) = 0;
virtual SequenceSortKey GetSortKey() const = 0;
virtual TaskSourceSortKey GetSortKey() const = 0;
// Sets TaskSource priority to |priority|.
void UpdatePriority(TaskPriority priority);
......
......@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task_source_sort_key.h"
namespace base {
namespace internal {
SequenceSortKey::SequenceSortKey(TaskPriority priority,
TimeTicks next_task_sequenced_time)
TaskSourceSortKey::TaskSourceSortKey(TaskPriority priority,
TimeTicks next_task_sequenced_time)
: priority_(priority),
next_task_sequenced_time_(next_task_sequenced_time) {}
bool SequenceSortKey::operator<=(const SequenceSortKey& other) const {
// This SequenceSortKey is considered more important than |other| if it has a
// higher priority or if it has the same priority but its next task was
bool TaskSourceSortKey::operator<=(const TaskSourceSortKey& other) const {
// This TaskSourceSortKey is considered more important than |other| if it has
// a higher priority or if it has the same priority but its next task was
// posted sooner than |other|'s.
const int priority_diff =
static_cast<int>(priority_) - static_cast<int>(other.priority_);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_TASK_THREAD_POOL_SEQUENCE_SORT_KEY_H_
#define BASE_TASK_THREAD_POOL_SEQUENCE_SORT_KEY_H_
#ifndef BASE_TASK_THREAD_POOL_TASK_SOURCE_SORT_KEY_H_
#define BASE_TASK_THREAD_POOL_TASK_SOURCE_SORT_KEY_H_
#include "base/base_export.h"
#include "base/task/task_traits.h"
......@@ -13,10 +13,10 @@ namespace base {
namespace internal {
// An immutable but assignable representation of the priority of a Sequence.
class BASE_EXPORT SequenceSortKey final {
class BASE_EXPORT TaskSourceSortKey final {
public:
SequenceSortKey() = default;
SequenceSortKey(TaskPriority priority, TimeTicks next_task_sequenced_time);
TaskSourceSortKey() = default;
TaskSourceSortKey(TaskPriority priority, TimeTicks next_task_sequenced_time);
TaskPriority priority() const { return priority_; }
TimeTicks next_task_sequenced_time() const {
......@@ -24,13 +24,13 @@ class BASE_EXPORT SequenceSortKey final {
}
// Lower sort key means more important.
bool operator<=(const SequenceSortKey& other) const;
bool operator<=(const TaskSourceSortKey& other) const;
bool operator==(const SequenceSortKey& other) const {
bool operator==(const TaskSourceSortKey& other) const {
return priority_ == other.priority_ &&
next_task_sequenced_time_ == other.next_task_sequenced_time_;
}
bool operator!=(const SequenceSortKey& other) const {
bool operator!=(const TaskSourceSortKey& other) const {
return !(other == *this);
}
......@@ -50,4 +50,4 @@ class BASE_EXPORT SequenceSortKey final {
} // namespace internal
} // namespace base
#endif // BASE_TASK_THREAD_POOL_SEQUENCE_SORT_KEY_H_
#endif // BASE_TASK_THREAD_POOL_TASK_SOURCE_SORT_KEY_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/task/task_traits.h"
#include "base/time/time.h"
......@@ -11,19 +11,19 @@
namespace base {
namespace internal {
TEST(SequenceSortKeyTest, OperatorLessThanOrEqual) {
SequenceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
TEST(TaskSourceSortKeyTest, OperatorLessThanOrEqual) {
TaskSourceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
EXPECT_LE(key_a, key_a);
EXPECT_FALSE(key_b <= key_a);
......@@ -68,19 +68,19 @@ TEST(SequenceSortKeyTest, OperatorLessThanOrEqual) {
EXPECT_LE(key_f, key_f);
}
TEST(SequenceSortKeyTest, OperatorEqual) {
SequenceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
TEST(TaskSourceSortKeyTest, OperatorEqual) {
TaskSourceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
EXPECT_EQ(key_a, key_a);
EXPECT_FALSE(key_b == key_a);
......@@ -125,19 +125,19 @@ TEST(SequenceSortKeyTest, OperatorEqual) {
EXPECT_EQ(key_f, key_f);
}
TEST(SequenceSortKeyTest, OperatorNotEqual) {
SequenceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
SequenceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
SequenceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
TEST(TaskSourceSortKeyTest, OperatorNotEqual) {
TaskSourceSortKey key_a(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_b(TaskPriority::USER_BLOCKING,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_c(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_d(TaskPriority::USER_VISIBLE,
TimeTicks::FromInternalValue(2000));
TaskSourceSortKey key_e(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(1000));
TaskSourceSortKey key_f(TaskPriority::BEST_EFFORT,
TimeTicks::FromInternalValue(2000));
EXPECT_FALSE(key_a != key_a);
EXPECT_NE(key_b, key_a);
......
......@@ -30,7 +30,7 @@
#include "base/task/thread_pool/delayed_task_manager.h"
#include "base/task/thread_pool/pooled_task_runner_delegate.h"
#include "base/task/thread_pool/sequence.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/task/thread_pool/task_tracker.h"
#include "base/task/thread_pool/test_task_factory.h"
#include "base/task/thread_pool/test_utils.h"
......
......@@ -23,10 +23,10 @@
#include "base/task/task_features.h"
#include "base/task/thread_pool/pooled_parallel_task_runner.h"
#include "base/task/thread_pool/pooled_sequenced_task_runner.h"
#include "base/task/thread_pool/sequence_sort_key.h"
#include "base/task/thread_pool/service_thread.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/task/thread_pool/thread_group_impl.h"
#include "base/task/thread_pool/worker_thread.h"
#include "base/threading/platform_thread.h"
......
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