Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "public/platform/WebCommon.h" | |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 namespace scheduler { | 14 namespace scheduler { |
| 14 namespace internal { | 15 namespace internal { |
| 15 | 16 |
| 16 using EnqueueOrder = uint64_t; | 17 // The enqueue order is used to uniquely order tasks. The primary ordering key |
| 18 // is the desired run time of a task, followed by the sequence number. Note the | |
| 19 // scheduler assumes sequence numbers will not overflow. | |
| 20 struct BLINK_PLATFORM_EXPORT EnqueueOrder { | |
| 21 base::TimeTicks delayed_run_time; | |
| 22 uint64_t sequence_num; | |
|
alex clarke (OOO till 29th)
2017/04/13 07:46:00
I wonder if we should have
using SequenceNum = ui
Sami
2017/04/18 10:47:49
Good idea, done.
| |
| 17 | 23 |
| 18 // TODO(scheduler-dev): Remove explicit casts when c++17 comes. | 24 bool is_null() const { return delayed_run_time.is_null() && !sequence_num; } |
| 19 enum class EnqueueOrderValues : EnqueueOrder { | 25 |
| 20 // Invalid EnqueueOrder. | 26 bool operator==(const EnqueueOrder& other) const; |
| 27 bool operator<=(const EnqueueOrder& other) const; | |
| 28 bool operator<(const EnqueueOrder& other) const; | |
| 29 }; | |
| 30 | |
| 31 std::ostream& operator<<(std::ostream&, const EnqueueOrder&); | |
| 32 | |
| 33 enum class EnqueueOrderSequenceNumberValues { | |
| 34 // Invalid sequence number. | |
| 21 NONE = 0, | 35 NONE = 0, |
| 22 | 36 |
| 23 // Earliest possible EnqueueOrder, to be used for fence blocking. | 37 // Earliest possible sequence number, to be used for fence blocking. |
| 24 BLOCKING_FENCE = 1, | 38 BLOCKING_FENCE = 1, |
| 25 FIRST = 2, | 39 FIRST = 2, |
| 26 }; | 40 }; |
| 27 | 41 |
| 28 // A 64bit integer used to provide ordering of tasks. NOTE The scheduler assumes | |
|
alex clarke (OOO till 29th)
2017/04/13 07:46:00
We should keep the comment about not overflowing.
Sami
2017/04/18 10:47:49
Yep, it's now further up the file where the enqueu
| |
| 29 // these values will not overflow. | |
| 30 class EnqueueOrderGenerator { | 42 class EnqueueOrderGenerator { |
| 31 public: | 43 public: |
| 32 EnqueueOrderGenerator(); | 44 EnqueueOrderGenerator(); |
| 33 ~EnqueueOrderGenerator(); | 45 ~EnqueueOrderGenerator(); |
| 34 | 46 |
| 35 // Returns a monotonically increasing integer, starting from one. Can be | 47 // Returns a monotonically increasing enqueue order, starting from one. Can be |
| 36 // called from any thread. | 48 // called from any thread. |
| 37 EnqueueOrder GenerateNext(); | 49 EnqueueOrder GenerateNext(base::TimeTicks delayed_run_time); |
| 38 | |
| 39 static bool IsValidEnqueueOrder(EnqueueOrder enqueue_order) { | |
| 40 return enqueue_order != 0ull; | |
| 41 } | |
| 42 | 50 |
| 43 private: | 51 private: |
| 44 base::Lock lock_; | 52 base::Lock lock_; |
| 45 EnqueueOrder enqueue_order_; | 53 uint64_t sequence_num_; |
| 46 }; | 54 }; |
| 47 | 55 |
| 48 } // namespace internal | 56 } // namespace internal |
| 49 } // namespace scheduler | 57 } // namespace scheduler |
| 50 } // namespace blink | 58 } // namespace blink |
| 51 | 59 |
| 52 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ | 60 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_ENQUEUE_ORDER_H_ |
| OLD | NEW |