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

Side by Side Diff: base/non_thread_safe.h

Issue 18677: Use PlatformThreadId, not int when dealing with thread ids. (Closed)
Patch Set: Addressing comments Created 11 years, 11 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/message_pump_glib.cc ('k') | base/platform_thread.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_NON_THREAD_SAFE_H__ 5 #ifndef BASE_NON_THREAD_SAFE_H__
6 #define BASE_NON_THREAD_SAFE_H__ 6 #define BASE_NON_THREAD_SAFE_H__
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/platform_thread.h"
9 10
10 // A helper class used to help verify that methods of a class are 11 // A helper class used to help verify that methods of a class are
11 // called from the same thread. One can inherit from this class and use 12 // called from the same thread. One can inherit from this class and use
12 // CalledOnValidThread() to verify. 13 // CalledOnValidThread() to verify.
13 // 14 //
14 // This is intended to be used with classes that appear to be thread safe, but 15 // This is intended to be used with classes that appear to be thread safe, but
15 // aren't. For example, a service or a singleton like the preferences system. 16 // aren't. For example, a service or a singleton like the preferences system.
16 // 17 //
17 // Example: 18 // Example:
18 // class MyClass : public NonThreadSafe { 19 // class MyClass : public NonThreadSafe {
19 // public: 20 // public:
20 // void Foo() { 21 // void Foo() {
21 // DCHECK(CalledOnValidThread()); 22 // DCHECK(CalledOnValidThread());
22 // ... (do stuff) ... 23 // ... (do stuff) ...
23 // } 24 // }
24 // } 25 // }
25 // 26 //
26 // In Release mode, CalledOnValidThread will always return true. 27 // In Release mode, CalledOnValidThread will always return true.
27 // 28 //
28 #ifndef NDEBUG 29 #ifndef NDEBUG
29 class NonThreadSafe { 30 class NonThreadSafe {
30 public: 31 public:
31 NonThreadSafe(); 32 NonThreadSafe();
32 ~NonThreadSafe(); 33 ~NonThreadSafe();
33 34
34 protected: 35 protected:
35 bool CalledOnValidThread() const; 36 bool CalledOnValidThread() const;
36 37
37 private: 38 private:
38 int valid_thread_id_; 39 PlatformThreadId valid_thread_id_;
39 }; 40 };
40 #else 41 #else
41 // Do nothing in release mode. 42 // Do nothing in release mode.
42 class NonThreadSafe { 43 class NonThreadSafe {
43 public: 44 public:
44 NonThreadSafe() {} 45 NonThreadSafe() {}
45 ~NonThreadSafe() {} 46 ~NonThreadSafe() {}
46 47
47 protected: 48 protected:
48 bool CalledOnValidThread() const { 49 bool CalledOnValidThread() const {
49 return true; 50 return true;
50 } 51 }
51 }; 52 };
52 #endif // NDEBUG 53 #endif // NDEBUG
53 54
54 #endif // BASE_NON_THREAD_SAFE_H__ 55 #endif // BASE_NON_THREAD_SAFE_H__
55 56
OLDNEW
« no previous file with comments | « base/message_pump_glib.cc ('k') | base/platform_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698