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

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

Issue 10332269: RefCounted types should not have public destructors, base/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/synchronization/waitable_event_watcher.h ('k') | base/threading/non_thread_safe_impl.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 // Classes deriving from NonThreadSafe may need to supress MSVC warning 4275: 9 // Classes deriving from NonThreadSafe may need to supress MSVC warning 4275:
10 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'. 10 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
(...skipping 11 matching lines...) Expand all
22 // 22 //
23 // Note: You should almost always use the NonThreadSafe class to get 23 // Note: You should almost always use the NonThreadSafe class to get
24 // the right version of the class for your build configuration. 24 // the right version of the class for your build configuration.
25 class NonThreadSafeDoNothing { 25 class NonThreadSafeDoNothing {
26 public: 26 public:
27 bool CalledOnValidThread() const { 27 bool CalledOnValidThread() const {
28 return true; 28 return true;
29 } 29 }
30 30
31 protected: 31 protected:
32 ~NonThreadSafeDoNothing() {}
32 void DetachFromThread() {} 33 void DetachFromThread() {}
33 }; 34 };
34 35
35 // NonThreadSafe is a helper class used to help verify that methods of a 36 // NonThreadSafe is a helper class used to help verify that methods of a
36 // class are called from the same thread. One can inherit from this class 37 // class are called from the same thread. One can inherit from this class
37 // and use CalledOnValidThread() to verify. 38 // and use CalledOnValidThread() to verify.
38 // 39 //
39 // This is intended to be used with classes that appear to be thread safe, but 40 // This is intended to be used with classes that appear to be thread safe, but
40 // aren't. For example, a service or a singleton like the preferences system. 41 // aren't. For example, a service or a singleton like the preferences system.
41 // 42 //
42 // Example: 43 // Example:
43 // class MyClass : public base::NonThreadSafe { 44 // class MyClass : public base::NonThreadSafe {
44 // public: 45 // public:
45 // void Foo() { 46 // void Foo() {
46 // DCHECK(CalledOnValidThread()); 47 // DCHECK(CalledOnValidThread());
47 // ... (do stuff) ... 48 // ... (do stuff) ...
48 // } 49 // }
49 // } 50 // }
50 // 51 //
51 // In Release mode, CalledOnValidThread will always return true. 52 // In Release mode, CalledOnValidThread will always return true.
52 // 53 //
53 #ifndef NDEBUG 54 #ifndef NDEBUG
54 class NonThreadSafe : public NonThreadSafeImpl { 55 typedef NonThreadSafeImpl NonThreadSafe;
55 };
56 #else 56 #else
57 class NonThreadSafe : public NonThreadSafeDoNothing { 57 typedef NonThreadSafeDoNothing NonThreadSafe;
58 };
59 #endif // NDEBUG 58 #endif // NDEBUG
60 59
61 } // namespace base 60 } // namespace base
62 61
63 #endif // BASE_NON_THREAD_SAFE_H_ 62 #endif // BASE_NON_THREAD_SAFE_H_
OLDNEW
« no previous file with comments | « base/synchronization/waitable_event_watcher.h ('k') | base/threading/non_thread_safe_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698