OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wait_chain.h" | 5 #include "base/win/wait_chain.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void WaitForMutexAcquired() { | 102 void WaitForMutexAcquired() { |
103 EXPECT_EQ(WAIT_OBJECT_0, | 103 EXPECT_EQ(WAIT_OBJECT_0, |
104 ::WaitForSingleObject(mutex_acquired_event_.Get(), INFINITE)); | 104 ::WaitForSingleObject(mutex_acquired_event_.Get(), INFINITE)); |
105 } | 105 } |
106 | 106 |
107 // Signal the thread to acquire the second mutex. | 107 // Signal the thread to acquire the second mutex. |
108 void SignalToAcquireMutex() { EXPECT_TRUE(::SetEvent(wait_event_.Get())); } | 108 void SignalToAcquireMutex() { EXPECT_TRUE(::SetEvent(wait_event_.Get())); } |
109 | 109 |
110 // Terminates the thread. | 110 // Terminates the thread. |
111 bool Terminate() { | 111 bool Terminate() { |
112 ScopedHandle thread_handle(::OpenThread(THREAD_TERMINATE, FALSE, GetTid())); | 112 ScopedHandle thread_handle(::OpenThread(THREAD_TERMINATE, FALSE, tid())); |
113 return ::TerminateThread(thread_handle.Get(), 0); | 113 return ::TerminateThread(thread_handle.Get(), 0); |
114 } | 114 } |
115 | 115 |
116 private: | 116 private: |
117 ScopedHandle wait_event_; | 117 ScopedHandle wait_event_; |
118 ScopedHandle mutex_acquired_event_; | 118 ScopedHandle mutex_acquired_event_; |
119 | 119 |
120 // The 2 mutex to acquire. | 120 // The 2 mutex to acquire. |
121 HANDLE mutex_1_; | 121 HANDLE mutex_1_; |
122 HANDLE mutex_2_; | 122 HANDLE mutex_2_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 Sleep(10); | 252 Sleep(10); |
253 | 253 |
254 // Create a few waiting threads to get a longer wait chain. | 254 // Create a few waiting threads to get a longer wait chain. |
255 std::unique_ptr<SingleTaskThread> waiting_thread_1 = | 255 std::unique_ptr<SingleTaskThread> waiting_thread_1 = |
256 CreateJoiningThread(deadlock_thread_1.get()); | 256 CreateJoiningThread(deadlock_thread_1.get()); |
257 std::unique_ptr<SingleTaskThread> waiting_thread_2 = | 257 std::unique_ptr<SingleTaskThread> waiting_thread_2 = |
258 CreateJoiningThread(waiting_thread_1.get()); | 258 CreateJoiningThread(waiting_thread_1.get()); |
259 | 259 |
260 WaitChainNodeVector wait_chain; | 260 WaitChainNodeVector wait_chain; |
261 bool is_deadlock; | 261 bool is_deadlock; |
262 ASSERT_TRUE(GetThreadWaitChain(waiting_thread_2->GetTid(), &wait_chain, | 262 ASSERT_TRUE(GetThreadWaitChain(waiting_thread_2->tid(), &wait_chain, |
263 &is_deadlock, nullptr, nullptr)); | 263 &is_deadlock, nullptr, nullptr)); |
264 | 264 |
265 EXPECT_EQ(9U, wait_chain.size()); | 265 EXPECT_EQ(9U, wait_chain.size()); |
266 EXPECT_TRUE(is_deadlock); | 266 EXPECT_TRUE(is_deadlock); |
267 EXPECT_TRUE(WaitChainStructureIsCorrect(wait_chain)); | 267 EXPECT_TRUE(WaitChainStructureIsCorrect(wait_chain)); |
268 EXPECT_FALSE(WaitChainIsCrossProcess(wait_chain)); | 268 EXPECT_FALSE(WaitChainIsCrossProcess(wait_chain)); |
269 | 269 |
270 ASSERT_TRUE(deadlock_thread_1->Terminate()); | 270 ASSERT_TRUE(deadlock_thread_1->Terminate()); |
271 | 271 |
272 // The SimpleThread API expect Join() to be called before destruction. | 272 // The SimpleThread API expect Join() to be called before destruction. |
(...skipping 18 matching lines...) Expand all Loading... |
291 // Create a few waiting threads to get a longer wait chain. | 291 // Create a few waiting threads to get a longer wait chain. |
292 std::unique_ptr<SingleTaskThread> waiting_thread_1 = | 292 std::unique_ptr<SingleTaskThread> waiting_thread_1 = |
293 CreateWaitingThread(mutex.Get()); | 293 CreateWaitingThread(mutex.Get()); |
294 std::unique_ptr<SingleTaskThread> waiting_thread_2 = | 294 std::unique_ptr<SingleTaskThread> waiting_thread_2 = |
295 CreateJoiningThread(waiting_thread_1.get()); | 295 CreateJoiningThread(waiting_thread_1.get()); |
296 std::unique_ptr<SingleTaskThread> waiting_thread_3 = | 296 std::unique_ptr<SingleTaskThread> waiting_thread_3 = |
297 CreateJoiningThread(waiting_thread_2.get()); | 297 CreateJoiningThread(waiting_thread_2.get()); |
298 | 298 |
299 WaitChainNodeVector wait_chain; | 299 WaitChainNodeVector wait_chain; |
300 bool is_deadlock; | 300 bool is_deadlock; |
301 ASSERT_TRUE(GetThreadWaitChain(waiting_thread_3->GetTid(), &wait_chain, | 301 ASSERT_TRUE(GetThreadWaitChain(waiting_thread_3->tid(), &wait_chain, |
302 &is_deadlock, nullptr, nullptr)); | 302 &is_deadlock, nullptr, nullptr)); |
303 | 303 |
304 EXPECT_EQ(7U, wait_chain.size()); | 304 EXPECT_EQ(7U, wait_chain.size()); |
305 EXPECT_FALSE(is_deadlock); | 305 EXPECT_FALSE(is_deadlock); |
306 EXPECT_TRUE(WaitChainStructureIsCorrect(wait_chain)); | 306 EXPECT_TRUE(WaitChainStructureIsCorrect(wait_chain)); |
307 EXPECT_TRUE(WaitChainIsCrossProcess(wait_chain)); | 307 EXPECT_TRUE(WaitChainIsCrossProcess(wait_chain)); |
308 | 308 |
309 // Unblock child process and wait for it to terminate. | 309 // Unblock child process and wait for it to terminate. |
310 ASSERT_TRUE(::SetEvent(sync_event.Get())); | 310 ASSERT_TRUE(::SetEvent(sync_event.Get())); |
311 ASSERT_TRUE(child_process.WaitForExit(nullptr)); | 311 ASSERT_TRUE(child_process.WaitForExit(nullptr)); |
312 | 312 |
313 // The SimpleThread API expect Join() to be called before destruction. | 313 // The SimpleThread API expect Join() to be called before destruction. |
314 waiting_thread_3->Join(); | 314 waiting_thread_3->Join(); |
315 } | 315 } |
316 | 316 |
317 } // namespace win | 317 } // namespace win |
318 } // namespace base | 318 } // namespace base |
OLD | NEW |