| 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 #ifndef BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ | 5 #ifndef BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ |
| 6 #define BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ | 6 #define BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/task_scheduler/scheduler_lock.h" | 15 #include "base/task_scheduler/scheduler_lock.h" |
| 16 #include "base/task_scheduler/sequence.h" | 16 #include "base/task_scheduler/sequence.h" |
| 17 #include "base/task_scheduler/sequence_sort_key.h" | 17 #include "base/task_scheduler/sequence_sort_key.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 // A PriorityQueue holds Sequences of Tasks. This class is thread-safe. | 23 // A PriorityQueue holds Sequences of Tasks. This class is thread-safe. |
| 24 class BASE_EXPORT PriorityQueue { | 24 class BASE_EXPORT PriorityQueue { |
| 25 public: | 25 public: |
| 26 // A Transaction can perform multiple operations atomically on a | 26 // A Transaction can perform multiple operations atomically on a |
| 27 // PriorityQueue. While a Transaction is alive, it is guaranteed that nothing | 27 // PriorityQueue. While a Transaction is alive, it is guaranteed that nothing |
| 28 // else will access the PriorityQueue. | 28 // else will access the PriorityQueue. |
| 29 // | 29 // |
| 30 // A WorkerThread needs to be able to Peek sequences from both its | 30 // A Worker needs to be able to Peek sequences from both its PriorityQueues |
| 31 // PriorityQueues (single-threaded and shared) and then Pop the sequence with | 31 // (single-threaded and shared) and then Pop the sequence with the highest |
| 32 // the highest priority. If the Peek and the Pop are done through the same | 32 // priority. If the Peek and the Pop are done through the same Transaction, it |
| 33 // Transaction, it is guaranteed that the PriorityQueue hasn't changed between | 33 // is guaranteed that the PriorityQueue hasn't changed between the 2 |
| 34 // the 2 operations. | 34 // operations. |
| 35 class BASE_EXPORT Transaction : public NonThreadSafe { | 35 class BASE_EXPORT Transaction : public NonThreadSafe { |
| 36 public: | 36 public: |
| 37 ~Transaction(); | 37 ~Transaction(); |
| 38 | 38 |
| 39 // Inserts |sequence| in the PriorityQueue with |sequence_sort_key|. | 39 // Inserts |sequence| in the PriorityQueue with |sequence_sort_key|. |
| 40 // Note: |sequence_sort_key| is required as a parameter instead of being | 40 // Note: |sequence_sort_key| is required as a parameter instead of being |
| 41 // extracted from |sequence| in Push() to avoid this Transaction having a | 41 // extracted from |sequence| in Push() to avoid this Transaction having a |
| 42 // lock interdependency with |sequence|. | 42 // lock interdependency with |sequence|. |
| 43 void Push(scoped_refptr<Sequence> sequence, | 43 void Push(scoped_refptr<Sequence> sequence, |
| 44 const SequenceSortKey& sequence_sort_key); | 44 const SequenceSortKey& sequence_sort_key); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 ContainerType container_; | 99 ContainerType container_; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(PriorityQueue); | 101 DISALLOW_COPY_AND_ASSIGN(PriorityQueue); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 } // namespace internal | 104 } // namespace internal |
| 105 } // namespace base | 105 } // namespace base |
| 106 | 106 |
| 107 #endif // BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ | 107 #endif // BASE_TASK_SCHEDULER_PRIORITY_QUEUE_H_ |
| OLD | NEW |