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

Side by Side Diff: base/threading/non_thread_safe.h

Issue 2869893003: New Sequence/Thread checking API. (Closed)
Patch Set: fix tests in non-dcheck builds, need fixture can't use lambdas Created 3 years, 7 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
« no previous file with comments | « base/sequence_checker_unittest.cc ('k') | base/threading/thread_checker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_THREADING_NON_THREAD_SAFE_H_ 5 #ifndef BASE_THREADING_NON_THREAD_SAFE_H_
6 #define BASE_THREADING_NON_THREAD_SAFE_H_ 6 #define BASE_THREADING_NON_THREAD_SAFE_H_
7 7
8 // Classes deriving from NonThreadSafe may need to suppress MSVC warning 4275: 8 // Classes deriving from NonThreadSafe may need to suppress MSVC warning 4275:
9 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'. 9 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
10 // There is a specific macro to do it: NON_EXPORTED_BASE(), defined in 10 // There is a specific macro to do it: NON_EXPORTED_BASE(), defined in
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 bool CalledOnValidThread() const { 24 bool CalledOnValidThread() const {
25 return true; 25 return true;
26 } 26 }
27 27
28 protected: 28 protected:
29 ~NonThreadSafeDoNothing() {} 29 ~NonThreadSafeDoNothing() {}
30 void DetachFromThread() {} 30 void DetachFromThread() {}
31 }; 31 };
32 32
33 // NonThreadSafe is a helper class used to help verify that methods of a 33 // DEPRECATED! Use base::SequenceChecker (for thread-safety) or
34 // class are called from the same thread. One can inherit from this class 34 // base::ThreadChecker (for thread-affinity) -- see their documentation for
35 // and use CalledOnValidThread() to verify. 35 // details. Use a checker as a protected member instead of inheriting from
36 // 36 // NonThreadSafe if you need subclasses to have access.
37 // This is intended to be used with classes that appear to be thread safe, but
38 // aren't. For example, a service or a singleton like the preferences system.
39 //
40 // Example:
41 // class MyClass : public base::NonThreadSafe {
42 // public:
43 // void Foo() {
44 // DCHECK(CalledOnValidThread());
45 // ... (do stuff) ...
46 // }
47 // }
48 //
49 // Note that base::ThreadChecker offers identical functionality to
50 // NonThreadSafe, but does not require inheritance. In general, it is preferable
51 // to have a base::ThreadChecker as a member, rather than inherit from
52 // NonThreadSafe. For more details about when to choose one over the other, see
53 // the documentation for base::ThreadChecker.
54 #if DCHECK_IS_ON() 37 #if DCHECK_IS_ON()
55 typedef NonThreadSafeImpl NonThreadSafe; 38 typedef NonThreadSafeImpl NonThreadSafe;
56 #else 39 #else
57 typedef NonThreadSafeDoNothing NonThreadSafe; 40 typedef NonThreadSafeDoNothing NonThreadSafe;
58 #endif // DCHECK_IS_ON() 41 #endif // DCHECK_IS_ON()
59 42
60 } // namespace base 43 } // namespace base
61 44
62 #endif // BASE_THREADING_NON_THREAD_SAFE_H_ 45 #endif // BASE_THREADING_NON_THREAD_SAFE_H_
OLDNEW
« no previous file with comments | « base/sequence_checker_unittest.cc ('k') | base/threading/thread_checker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698