OLD | NEW |
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 #include "base/win/scoped_handle.h" | 5 #include "base/win/scoped_handle.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER; | 28 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER; |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 namespace base { | 32 namespace base { |
33 namespace win { | 33 namespace win { |
34 | 34 |
35 // Static. | 35 // Static. |
36 void VerifierTraits::StartTracking(HANDLE handle, const void* owner, | 36 void VerifierTraits::StartTracking(HANDLE handle, const void* owner, |
37 const void* pc1, const void* pc2) { | 37 const void* pc1, const void* pc2) { |
38 if (OSInfo::GetInstance()->version() > VERSION_XP) | |
39 return; | |
40 | |
41 // Grab the thread id before the lock. | 38 // Grab the thread id before the lock. |
42 DWORD thread_id = GetCurrentThreadId(); | 39 DWORD thread_id = GetCurrentThreadId(); |
43 | 40 |
44 AutoLock lock(g_lock.Get()); | 41 AutoLock lock(g_lock.Get()); |
45 | 42 |
46 if (handle == INVALID_HANDLE_VALUE) { | 43 if (handle == INVALID_HANDLE_VALUE) { |
47 // Cannot track this handle. | 44 // Cannot track this handle. |
48 g_owner_set.Get().insert(owner); | 45 g_owner_set.Get().insert(owner); |
49 return; | 46 return; |
50 } | 47 } |
51 | 48 |
52 Info handle_info = { owner, pc1, pc2, thread_id }; | 49 Info handle_info = { owner, pc1, pc2, thread_id }; |
53 std::pair<HANDLE, Info> item(handle, handle_info); | 50 std::pair<HANDLE, Info> item(handle, handle_info); |
54 std::pair<HandleMap::iterator, bool> result = g_handle_map.Get().insert(item); | 51 std::pair<HandleMap::iterator, bool> result = g_handle_map.Get().insert(item); |
55 if (!result.second) { | 52 if (!result.second) { |
56 Info other = result.first->second; | 53 Info other = result.first->second; |
57 debug::Alias(&other); | 54 debug::Alias(&other); |
58 CHECK(false); | 55 CHECK(false); |
59 } | 56 } |
60 } | 57 } |
61 | 58 |
62 // Static. | 59 // Static. |
63 void VerifierTraits::StopTracking(HANDLE handle, const void* owner, | 60 void VerifierTraits::StopTracking(HANDLE handle, const void* owner, |
64 const void* pc1, const void* pc2) { | 61 const void* pc1, const void* pc2) { |
65 if (OSInfo::GetInstance()->version() > VERSION_XP) | |
66 return; | |
67 | |
68 AutoLock lock(g_lock.Get()); | 62 AutoLock lock(g_lock.Get()); |
69 HandleMap::iterator i = g_handle_map.Get().find(handle); | 63 HandleMap::iterator i = g_handle_map.Get().find(handle); |
70 if (i == g_handle_map.Get().end()) { | 64 if (i == g_handle_map.Get().end()) { |
71 std::set<const void*>::iterator j = g_owner_set.Get().find(owner); | 65 std::set<const void*>::iterator j = g_owner_set.Get().find(owner); |
72 if (j != g_owner_set.Get().end()) { | 66 if (j != g_owner_set.Get().end()) { |
73 g_owner_set.Get().erase(j); | 67 g_owner_set.Get().erase(j); |
74 return; | 68 return; |
75 } | 69 } |
76 CHECK(false); | 70 CHECK(false); |
77 } | 71 } |
78 | 72 |
79 Info other = i->second; | 73 Info other = i->second; |
80 if (other.owner != owner) { | 74 if (other.owner != owner) { |
81 debug::Alias(&other); | 75 debug::Alias(&other); |
82 CHECK(false); | 76 CHECK(false); |
83 } | 77 } |
84 | 78 |
85 g_handle_map.Get().erase(i); | 79 g_handle_map.Get().erase(i); |
86 } | 80 } |
87 | 81 |
88 } // namespace win | 82 } // namespace win |
89 } // namespace base | 83 } // namespace base |
OLD | NEW |