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

Unified Diff: base/threading/non_thread_safe.h

Issue 6599004: Modify ThreadChecker and NonThreadSafe so that their functionality is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to current lkgr Created 9 years, 10 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/threading/non_thread_safe.cc » ('j') | net/disk_cache/block_files.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/non_thread_safe.h
diff --git a/base/threading/non_thread_safe.h b/base/threading/non_thread_safe.h
index 868a031e2f6984258e59687daaaa08379f3a1430..68206c3195cf11a5b7e36f14fec5d17bc50ec36e 100644
--- a/base/threading/non_thread_safe.h
+++ b/base/threading/non_thread_safe.h
@@ -10,9 +10,12 @@
namespace base {
-// A helper class used to help verify that methods of a class are
-// called from the same thread. One can inherit from this class and use
-// CalledOnValidThread() to verify.
+class NonThreadSafeImpl;
+class NonThreadSafeDoNothing;
+
+// NonThreadSafe is a helper class used to help verify that methods of a
+// class are called from the same thread. One can inherit from this class
+// and use CalledOnValidThread() to verify.
//
// This is intended to be used with classes that appear to be thread safe, but
// aren't. For example, a service or a singleton like the preferences system.
@@ -29,9 +32,20 @@ namespace base {
// In Release mode, CalledOnValidThread will always return true.
//
#ifndef NDEBUG
-class NonThreadSafe {
+typedef NonThreadSafeImpl NonThreadSafe;
+#else
+typedef NonThreadSafeDoNothing NonThreadSafe;
+#endif // NDEBUG
+
+// Full implementation of NonThreadSafe, for debug mode or for occasional
+// temporary use in release mode e.g. when you need to CHECK on a thread
+// bug that only occurs in the wild.
+//
+// Note: You should almost always use the NonThreadSafe typedef to get
+// the right version of the class.
+class NonThreadSafeImpl {
public:
- ~NonThreadSafe();
+ ~NonThreadSafeImpl();
bool CalledOnValidThread() const;
@@ -44,11 +58,14 @@ class NonThreadSafe {
void DetachFromThread();
private:
- ThreadChecker thread_checker_;
+ ThreadCheckerImpl thread_checker_;
};
-#else
-// Do nothing in release mode.
-class NonThreadSafe {
+
+// Do nothing implementation of NonThreadSafe, for release mode.
+//
+// Note: You should almost always use the NonThreadSafe typedef to get
+// the right version of the class.
+class NonThreadSafeDoNothing {
public:
bool CalledOnValidThread() const {
return true;
@@ -57,7 +74,6 @@ class NonThreadSafe {
protected:
void DetachFromThread() {}
};
-#endif // NDEBUG
} // namespace base
« no previous file with comments | « no previous file | base/threading/non_thread_safe.cc » ('j') | net/disk_cache/block_files.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698