OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_SEQUENCE_TOKEN_H_ |
| 6 #define BASE_SEQUENCE_TOKEN_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/macros.h" |
| 10 |
| 11 namespace base { |
| 12 |
| 13 // A token that identifies a series of sequenced tasks (i.e. tasks that run one |
| 14 // at a time in posting order). |
| 15 class BASE_EXPORT SequenceToken { |
| 16 public: |
| 17 // Instantiates an invalid SequenceToken. |
| 18 SequenceToken() = default; |
| 19 |
| 20 // Explicitly allow copy. |
| 21 SequenceToken(const SequenceToken& other) = default; |
| 22 SequenceToken& operator=(const SequenceToken& other) = default; |
| 23 |
| 24 // An invalid SequenceToken is not equal to any other SequenceToken, including |
| 25 // other invalid SequenceTokens. |
| 26 bool operator==(const SequenceToken& other) const; |
| 27 bool operator!=(const SequenceToken& other) const; |
| 28 |
| 29 // Returns true if this is a valid SequenceToken. |
| 30 bool IsValid() const; |
| 31 |
| 32 // Returns a valid SequenceToken which isn't equal to any previously returned |
| 33 // SequenceToken. |
| 34 static SequenceToken Create(); |
| 35 |
| 36 // Returns the SequenceToken associated with the task running on the current |
| 37 // thread, as determined by the active ScopedSetSequenceTokenForCurrentThread |
| 38 // if any. |
| 39 static SequenceToken GetForCurrentThread(); |
| 40 |
| 41 private: |
| 42 SequenceToken(int token) : token_(token) {} |
| 43 |
| 44 static constexpr int kInvalidSequenceToken = -1; |
| 45 int token_ = kInvalidSequenceToken; |
| 46 }; |
| 47 |
| 48 // Throughout its lifetime, determines the value returned by |
| 49 // SequenceToken::GetForCurrentThread(). |
| 50 class BASE_EXPORT ScopedSetSequenceTokenForCurrentThread { |
| 51 public: |
| 52 ScopedSetSequenceTokenForCurrentThread(const SequenceToken& token); |
| 53 ~ScopedSetSequenceTokenForCurrentThread(); |
| 54 |
| 55 private: |
| 56 friend class SequenceToken; |
| 57 |
| 58 const SequenceToken token_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(ScopedSetSequenceTokenForCurrentThread); |
| 61 }; |
| 62 |
| 63 } // namespace base |
| 64 |
| 65 #endif // BASE_SEQUENCE_TOKEN_H_ |
OLD | NEW |