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 namespace internal { | |
gab
2016/07/21 21:14:24
I think internal:: should be reserved for implemen
fdoray
2016/07/25 13:24:28
Done.
| |
13 | |
14 // A token that identifies a series of sequenced tasks (i.e. tasks that run one | |
15 // at a time in posting order). | |
16 class BASE_EXPORT SequenceToken { | |
17 public: | |
18 // Instantiates an invalid SequenceToken. | |
19 SequenceToken() = default; | |
20 | |
21 // Explicitly allow copy. | |
22 SequenceToken(const SequenceToken& other) = default; | |
23 SequenceToken& operator=(const SequenceToken& other) = default; | |
24 | |
25 bool operator==(const SequenceToken& other) const; | |
26 bool operator!=(const SequenceToken& other) const; | |
27 | |
28 // Returns true if this is a valid SequenceToken. | |
29 bool IsValid() const; | |
30 | |
31 // Returns a valid SequenceToken which isn't equal to any previously returned | |
32 // SequenceToken. | |
33 static SequenceToken Create(); | |
34 | |
35 // Returns the SequenceToken associated with the task running on the current | |
36 // thread, as determined by the active ScopedSetCurrentSequenceToken if any. | |
37 static SequenceToken GetCurrent(); | |
38 | |
39 private: | |
40 SequenceToken(int token) : token_(token) {} | |
41 | |
42 static constexpr int kInvalidSequenceToken = -1; | |
43 int token_ = kInvalidSequenceToken; | |
44 }; | |
45 | |
46 // Throughout its lifetime, determines the value returned by | |
47 // SequenceToken::GetCurrent(). | |
48 class BASE_EXPORT ScopedSetCurrentSequenceToken { | |
49 public: | |
50 ScopedSetCurrentSequenceToken(const SequenceToken& token); | |
51 ~ScopedSetCurrentSequenceToken(); | |
52 | |
53 private: | |
54 friend class SequenceToken; | |
55 | |
56 const SequenceToken token_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ScopedSetCurrentSequenceToken); | |
59 }; | |
60 | |
61 } // namespace internal | |
62 } // namespace base | |
63 | |
64 #endif // BASE_SEQUENCE_TOKEN_H_ | |
OLD | NEW |