Chromium Code Reviews| Index: base/task_scheduler/sequence.h |
| diff --git a/base/task_scheduler/sequence.h b/base/task_scheduler/sequence.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b175d90fa737218ded5c9094d8db9e8f1f722f4e |
| --- /dev/null |
| +++ b/base/task_scheduler/sequence.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 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. |
| + |
| +#ifndef BASE_TASK_SCHEDULER_SEQUENCE_H_ |
| +#define BASE_TASK_SCHEDULER_SEQUENCE_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include <queue> |
| + |
| +#include "base/base_export.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/task_scheduler/scheduler_lock.h" |
| +#include "base/task_scheduler/sequence_sort_key.h" |
| +#include "base/task_scheduler/task.h" |
| +#include "base/task_scheduler/task_traits.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +// A sequence holds tasks that must be executed in posting order. This class is |
| +// thread-safe. |
| +class BASE_EXPORT Sequence : public RefCountedThreadSafe<Sequence> { |
| + public: |
| + Sequence(); |
| + |
| + // Adds |task| at the end of the sequence's queue. |prev_num_tasks| is set to |
| + // the number of tasks that were in the sequence prior to the push. |
| + void PushTask(scoped_ptr<Task> task, size_t* prev_num_tasks); |
|
gab
2016/02/18 03:00:46
Return |prev_num_tasks| instead of using an out-pa
fdoray
2016/02/18 14:56:12
Done.
|
| + |
| + // Returns the sequence in front of the sequence's queue, if any. |
|
fdoray
2016/02/18 01:46:11
Returns the *task
fdoray
2016/02/18 14:56:12
Done.
|
| + const Task* PeekTask(); |
| + |
| + // Removes the task in front of the sequence's queue. |new_num_tasks| is set |
| + // to the number of tasks that are in the sequence right after the pop. This |
| + // cannot be called on an empty sequence. |
| + void PopTask(size_t* new_num_tasks); |
|
gab
2016/02/18 03:00:46
Same comment here, use return value and try to mak
fdoray
2016/02/18 14:56:12
Done.
|
| + |
| + // Returns a sort key to use when inserting the sequence in a priority queue. |
|
gab
2016/02/18 03:00:46
s/sort key/SequenceSortKey/
fdoray
2016/02/18 14:56:12
Done.
|
| + // This cannot be called on an empty sequence. |
| + SequenceSortKey GetSortKey(); |
| + |
| + private: |
| + friend class RefCountedThreadSafe<Sequence>; |
| + ~Sequence(); |
| + |
| + // Controls access to all members. |
| + SchedulerLock lock_; |
| + |
| + // Queue of tasks to execute. |
| + std::queue<scoped_ptr<Task>> queue_; |
| + |
| + // Number of tasks contained in the sequence for each priority. |
| + size_t num_tasks_per_priority_[kNumTaskPriorities]; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Sequence); |
| +}; |
| + |
| +} // namespace internal |
| +} // namespace base |
| + |
| +#endif // BASE_TASK_SCHEDULER_SEQUENCE_H_ |