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

Unified Diff: base/sequence_token.h

Issue 2213263002: Make ThreadChecker::CalledOnValidThread() return true when called from the same task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab #6 (fix comment) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/sequence_token.cc » ('j') | base/sequence_token.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sequence_token.h
diff --git a/base/sequence_token.h b/base/sequence_token.h
index 8d1398ea3c592f082cddcc607733795382b4f028..1f335281285f959812c9e738443bab466e27af13 100644
--- a/base/sequence_token.h
+++ b/base/sequence_token.h
@@ -45,17 +45,63 @@ class BASE_EXPORT SequenceToken {
int token_ = kInvalidSequenceToken;
};
-// Throughout its lifetime, determines the value returned by
-// SequenceToken::GetForCurrentThread().
+// A token that identifies a task.
+//
+// This is used by ThreadCheckerImpl to determine whether calls to
+// CalledOnValidThread() come from the same task and hence are deterministically
+// single-threaded (vs. calls coming from different sequenced or parallel tasks,
+// which may or may not run on the same thread).
+class BASE_EXPORT TaskToken {
+ public:
+ // Instantiates an invalid TaskToken.
+ TaskToken() = default;
+
+ // Explicitly allow copy.
+ TaskToken(const TaskToken& other) = default;
+ TaskToken& operator=(const TaskToken& other) = default;
+
+ // An invalid TaskToken is not equal to any other TaskToken, including
+ // other invalid TaskTokens.
+ bool operator==(const TaskToken& other) const;
+ bool operator!=(const TaskToken& other) const;
+
+ // Returns true if this is a valid TaskToken.
+ bool IsValid() const;
+
+ // In the scope of a ScopedSetSequenceTokenForCurrentThread, returns a valid
+ // TaskToken which isn't equal to any TaskToken returned in the scope of a
+ // different ScopedSetSequenceTokenForCurrentThread. Otherwise, returns an
+ // invalid TaskToken.
+ static TaskToken GetForCurrentThread();
+
+ private:
+ friend class ScopedSetSequenceTokenForCurrentThread;
+
+ TaskToken(int token) : token_(token) {}
Lei Zhang 2016/08/08 23:21:26 explicit
gab 2016/08/09 15:50:15 Done.
+
+ // Returns a valid TaskToken which isn't equal to any previously returned
+ // TaskToken. This is private as it only meant to be instantiated by
+ // ScopedSetSequenceTokenForCurrentThread.
+ static TaskToken Create();
+
+ static constexpr int kInvalidTaskToken = -1;
+ int token_ = kInvalidTaskToken;
+};
+
+// Instantiate this in the scope where a single task runs.
class BASE_EXPORT ScopedSetSequenceTokenForCurrentThread {
public:
- ScopedSetSequenceTokenForCurrentThread(const SequenceToken& token);
+ // Throughout the lifetime of the constructed object,
+ // SequenceToken::GetForCurrentThread() will return |sequence_token| and
+ // TaskToken::GetForCurrentThread() will return a TaskToken which is not equal
+ // to any TaskToken returned in the scope of another
+ // ScopedSetSequenceTokenForCurrentThread.
+ ScopedSetSequenceTokenForCurrentThread(const SequenceToken& sequence_token);
~ScopedSetSequenceTokenForCurrentThread();
private:
- friend class SequenceToken;
-
- const SequenceToken token_;
+ const SequenceToken sequence_token_;
+ const TaskToken task_token_;
DISALLOW_COPY_AND_ASSIGN(ScopedSetSequenceTokenForCurrentThread);
};
« no previous file with comments | « no previous file | base/sequence_token.cc » ('j') | base/sequence_token.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698