1 // Copyright 2018 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TASK_SEQUENCE_MANAGER_ENQUEUE_ORDER_H_ 6 #define BASE_TASK_SEQUENCE_MANAGER_ENQUEUE_ORDER_H_ 7 8 #include <stdint.h> 9 10 #include <limits> 11 12 namespace base { 13 namespace sequence_manager { 14 15 namespace internal { 16 class EnqueueOrderGenerator; 17 } 18 19 // 64-bit number which is used to order tasks. 20 // SequenceManager assumes this number will never overflow. 21 class EnqueueOrder { 22 public: EnqueueOrder()23 EnqueueOrder() : value_(kNone) {} 24 ~EnqueueOrder() = default; 25 none()26 static EnqueueOrder none() { return EnqueueOrder(kNone); } blocking_fence()27 static EnqueueOrder blocking_fence() { return EnqueueOrder(kBlockingFence); } 28 29 // Returns an EnqueueOrder that compares greater than any other EnqueueOrder. max()30 static EnqueueOrder max() { 31 return EnqueueOrder(std::numeric_limits<uint64_t>::max()); 32 } 33 34 // It's okay to use EnqueueOrder in boolean expressions keeping in mind 35 // that some non-zero values have a special meaning. uint64_t()36 operator uint64_t() const { return value_; } 37 FromIntForTesting(uint64_t value)38 static EnqueueOrder FromIntForTesting(uint64_t value) { 39 return EnqueueOrder(value); 40 } 41 42 private: 43 // EnqueueOrderGenerator is the only class allowed to create an EnqueueOrder 44 // with a non-default constructor. 45 friend class internal::EnqueueOrderGenerator; 46 EnqueueOrder(uint64_t value)47 explicit EnqueueOrder(uint64_t value) : value_(value) {} 48 49 enum SpecialValues : uint64_t { 50 kNone = 0, 51 kBlockingFence = 1, 52 kFirst = 2, 53 }; 54 55 uint64_t value_; 56 }; 57 58 } // namespace sequence_manager 59 } // namespace base 60 61 #endif // BASE_TASK_SEQUENCE_MANAGER_ENQUEUE_ORDER_H_ 62