Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: base/sequence_token.h

Issue 2165663003: TaskScheduler: Add SequenceToken and ScopedSetSequenceTokenForCurrentThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: invalid SequenceTokens are not equal Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 bool operator==(const SequenceToken& other) const;
danakj 2016/07/26 19:34:37 Can you document that an invalid token is not equa
fdoray 2016/07/26 20:35:45 Done.
25 bool operator!=(const SequenceToken& other) const;
26
27 // Returns true if this is a valid SequenceToken.
28 bool IsValid() const;
29
30 // Returns a valid SequenceToken which isn't equal to any previously returned
31 // SequenceToken.
32 static SequenceToken Create();
33
34 // Returns the SequenceToken associated with the task running on the current
35 // thread, as determined by the active ScopedSetCurrentSequenceToken if any.
36 static SequenceToken GetCurrent();
danakj 2016/07/26 19:34:37 nit: I'ld like GetForCurrentThread() a bit better
fdoray 2016/07/26 20:35:45 Done.
37
38 private:
39 SequenceToken(int token) : token_(token) {}
40
41 static constexpr int kInvalidSequenceToken = -1;
42 int token_ = kInvalidSequenceToken;
43 };
44
45 // Throughout its lifetime, determines the value returned by
46 // SequenceToken::GetCurrent().
47 class BASE_EXPORT ScopedSetCurrentSequenceToken {
danakj 2016/07/26 19:34:37 and ScopedSetSequenceTokenForCurrentThread?
fdoray 2016/07/26 20:35:45 Done.
48 public:
49 ScopedSetCurrentSequenceToken(const SequenceToken& token);
50 ~ScopedSetCurrentSequenceToken();
51
52 private:
53 friend class SequenceToken;
54
55 const SequenceToken token_;
56
57 DISALLOW_COPY_AND_ASSIGN(ScopedSetCurrentSequenceToken);
58 };
59
60 } // namespace base
61
62 #endif // BASE_SEQUENCE_TOKEN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698