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 #include "base/thread_checker.h" | 5 #include "base/thread_checker.h" |
6 | 6 |
7 // This code is only done in debug builds. | 7 // This code is only done in debug builds. |
8 #ifndef NDEBUG | 8 #ifndef NDEBUG |
9 | 9 |
10 ThreadChecker::ThreadChecker() { | 10 ThreadChecker::ThreadChecker() { |
11 EnsureThreadIdAssigned(); | 11 EnsureThreadIdAssigned(); |
12 } | 12 } |
13 | 13 |
| 14 ThreadChecker::~ThreadChecker() {} |
| 15 |
14 bool ThreadChecker::CalledOnValidThread() const { | 16 bool ThreadChecker::CalledOnValidThread() const { |
15 EnsureThreadIdAssigned(); | 17 EnsureThreadIdAssigned(); |
16 return *valid_thread_id_ == PlatformThread::CurrentId(); | 18 return *valid_thread_id_ == PlatformThread::CurrentId(); |
17 } | 19 } |
18 | 20 |
19 void ThreadChecker::DetachFromThread() { | 21 void ThreadChecker::DetachFromThread() { |
20 valid_thread_id_.reset(); | 22 valid_thread_id_.reset(); |
21 } | 23 } |
22 | 24 |
23 void ThreadChecker::EnsureThreadIdAssigned() const { | 25 void ThreadChecker::EnsureThreadIdAssigned() const { |
24 if (valid_thread_id_.get()) | 26 if (valid_thread_id_.get()) |
25 return; | 27 return; |
26 valid_thread_id_.reset(new PlatformThreadId(PlatformThread::CurrentId())); | 28 valid_thread_id_.reset(new PlatformThreadId(PlatformThread::CurrentId())); |
27 } | 29 } |
28 | 30 |
29 #endif // NDEBUG | 31 #endif // NDEBUG |
OLD | NEW |