OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_THREAD_CHECKER_H_ | 5 #ifndef BASE_THREAD_CHECKER_H_ |
6 #define BASE_THREAD_CHECKER_H_ | 6 #define BASE_THREAD_CHECKER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/platform_thread.h" | 9 #include "base/platform_thread.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // ... (do stuff) ... | 28 // ... (do stuff) ... |
29 // } | 29 // } |
30 // } | 30 // } |
31 // | 31 // |
32 // In Release mode, CalledOnValidThread will always return true. | 32 // In Release mode, CalledOnValidThread will always return true. |
33 // | 33 // |
34 #ifndef NDEBUG | 34 #ifndef NDEBUG |
35 class ThreadChecker { | 35 class ThreadChecker { |
36 public: | 36 public: |
37 ThreadChecker(); | 37 ThreadChecker(); |
| 38 ~ThreadChecker(); |
38 | 39 |
39 bool CalledOnValidThread() const; | 40 bool CalledOnValidThread() const; |
40 | 41 |
41 // Changes the thread that is checked for in CalledOnValidThread. This may | 42 // Changes the thread that is checked for in CalledOnValidThread. This may |
42 // be useful when an object may be created on one thread and then used | 43 // be useful when an object may be created on one thread and then used |
43 // exclusively on another thread. | 44 // exclusively on another thread. |
44 void DetachFromThread(); | 45 void DetachFromThread(); |
45 | 46 |
46 private: | 47 private: |
47 void EnsureThreadIdAssigned() const; | 48 void EnsureThreadIdAssigned() const; |
48 | 49 |
49 // This is mutable so that CalledOnValidThread can set it. | 50 // This is mutable so that CalledOnValidThread can set it. |
50 mutable scoped_ptr<PlatformThreadId> valid_thread_id_; | 51 mutable scoped_ptr<PlatformThreadId> valid_thread_id_; |
51 }; | 52 }; |
52 #else | 53 #else |
53 // Do nothing in release mode. | 54 // Do nothing in release mode. |
54 class ThreadChecker { | 55 class ThreadChecker { |
55 public: | 56 public: |
56 bool CalledOnValidThread() const { | 57 bool CalledOnValidThread() const { |
57 return true; | 58 return true; |
58 } | 59 } |
59 | 60 |
60 void DetachFromThread() {} | 61 void DetachFromThread() {} |
61 }; | 62 }; |
62 #endif // NDEBUG | 63 #endif // NDEBUG |
63 | 64 |
64 #endif // BASE_THREAD_CHECKER_H_ | 65 #endif // BASE_THREAD_CHECKER_H_ |
OLD | NEW |