enqueue_order.h 1.6 KB

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