| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/task_scheduler/priority_queue.h" | 5 #include "base/task_scheduler/priority_queue.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/task_scheduler/sequence.h" | 15 #include "base/task_scheduler/sequence.h" |
| 14 #include "base/task_scheduler/task.h" | 16 #include "base/task_scheduler/task.h" |
| 15 #include "base/task_scheduler/task_traits.h" | 17 #include "base/task_scheduler/task_traits.h" |
| 16 #include "base/test/gtest_util.h" | 18 #include "base/test/gtest_util.h" |
| 17 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
| 18 #include "base/threading/simple_thread.h" | 20 #include "base/threading/simple_thread.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 54 |
| 53 DISALLOW_COPY_AND_ASSIGN(ThreadBeginningTransaction); | 55 DISALLOW_COPY_AND_ASSIGN(ThreadBeginningTransaction); |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 } // namespace | 58 } // namespace |
| 57 | 59 |
| 58 TEST(TaskSchedulerPriorityQueueTest, PushPopPeek) { | 60 TEST(TaskSchedulerPriorityQueueTest, PushPopPeek) { |
| 59 // Create test sequences. | 61 // Create test sequences. |
| 60 scoped_refptr<Sequence> sequence_a(new Sequence); | 62 scoped_refptr<Sequence> sequence_a(new Sequence); |
| 61 sequence_a->PushTask(MakeUnique<Task>( | 63 sequence_a->PushTask(MakeUnique<Task>( |
| 62 FROM_HERE, Closure(), | 64 FROM_HERE, Bind(&DoNothing), |
| 63 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE), TimeDelta())); | 65 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE), TimeDelta())); |
| 64 SequenceSortKey sort_key_a = sequence_a->GetSortKey(); | 66 SequenceSortKey sort_key_a = sequence_a->GetSortKey(); |
| 65 | 67 |
| 66 scoped_refptr<Sequence> sequence_b(new Sequence); | 68 scoped_refptr<Sequence> sequence_b(new Sequence); |
| 67 sequence_b->PushTask(MakeUnique<Task>( | 69 sequence_b->PushTask(MakeUnique<Task>( |
| 68 FROM_HERE, Closure(), | 70 FROM_HERE, Bind(&DoNothing), |
| 69 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), TimeDelta())); | 71 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), TimeDelta())); |
| 70 SequenceSortKey sort_key_b = sequence_b->GetSortKey(); | 72 SequenceSortKey sort_key_b = sequence_b->GetSortKey(); |
| 71 | 73 |
| 72 scoped_refptr<Sequence> sequence_c(new Sequence); | 74 scoped_refptr<Sequence> sequence_c(new Sequence); |
| 73 sequence_c->PushTask(MakeUnique<Task>( | 75 sequence_c->PushTask(MakeUnique<Task>( |
| 74 FROM_HERE, Closure(), | 76 FROM_HERE, Bind(&DoNothing), |
| 75 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), TimeDelta())); | 77 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), TimeDelta())); |
| 76 SequenceSortKey sort_key_c = sequence_c->GetSortKey(); | 78 SequenceSortKey sort_key_c = sequence_c->GetSortKey(); |
| 77 | 79 |
| 78 scoped_refptr<Sequence> sequence_d(new Sequence); | 80 scoped_refptr<Sequence> sequence_d(new Sequence); |
| 79 sequence_d->PushTask(MakeUnique<Task>( | 81 sequence_d->PushTask(MakeUnique<Task>( |
| 80 FROM_HERE, Closure(), TaskTraits().WithPriority(TaskPriority::BACKGROUND), | 82 FROM_HERE, Bind(&DoNothing), |
| 81 TimeDelta())); | 83 TaskTraits().WithPriority(TaskPriority::BACKGROUND), TimeDelta())); |
| 82 SequenceSortKey sort_key_d = sequence_d->GetSortKey(); | 84 SequenceSortKey sort_key_d = sequence_d->GetSortKey(); |
| 83 | 85 |
| 84 // Create a PriorityQueue and a Transaction. | 86 // Create a PriorityQueue and a Transaction. |
| 85 PriorityQueue pq; | 87 PriorityQueue pq; |
| 86 auto transaction(pq.BeginTransaction()); | 88 auto transaction(pq.BeginTransaction()); |
| 87 EXPECT_TRUE(transaction->IsEmpty()); | 89 EXPECT_TRUE(transaction->IsEmpty()); |
| 88 | 90 |
| 89 // Push |sequence_a| in the PriorityQueue. It becomes the sequence with the | 91 // Push |sequence_a| in the PriorityQueue. It becomes the sequence with the |
| 90 // highest priority. | 92 // highest priority. |
| 91 transaction->Push(sequence_a, sort_key_a); | 93 transaction->Push(sequence_a, sort_key_a); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 164 |
| 163 // End the Transaction on the current thread. | 165 // End the Transaction on the current thread. |
| 164 transaction.reset(); | 166 transaction.reset(); |
| 165 | 167 |
| 166 // The other thread should exit after its call to BeginTransaction() returns. | 168 // The other thread should exit after its call to BeginTransaction() returns. |
| 167 thread_beginning_transaction.Join(); | 169 thread_beginning_transaction.Join(); |
| 168 } | 170 } |
| 169 | 171 |
| 170 } // namespace internal | 172 } // namespace internal |
| 171 } // namespace base | 173 } // namespace base |
| OLD | NEW |