OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/lock.h" | 6 #include "base/lock.h" |
7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
8 #include "base/simple_thread.h" | 8 #include "base/simple_thread.h" |
9 #include "base/thread_collision_warner.h" | 9 #include "base/thread_collision_warner.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 DFAKE_SCOPED_LOCK(warner); | 107 DFAKE_SCOPED_LOCK(warner); |
108 EXPECT_FALSE(local_reporter->fail_state()); | 108 EXPECT_FALSE(local_reporter->fail_state()); |
109 } // Unpin section. | 109 } // Unpin section. |
110 } | 110 } |
111 | 111 |
112 TEST(ThreadCollisionTest, MTBookCriticalSectionTest) { | 112 TEST(ThreadCollisionTest, MTBookCriticalSectionTest) { |
113 class NonThreadSafeQueue { | 113 class NonThreadSafeQueue { |
114 public: | 114 public: |
115 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 115 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
116 #if !defined(NDEBUG) | 116 #if !defined(NDEBUG) |
117 : push_pop_(asserter) | 117 : push_pop_(asserter) { |
| 118 #else |
| 119 { |
| 120 delete asserter; |
118 #endif | 121 #endif |
119 { } | 122 } |
120 | 123 |
121 void push(int value) { | 124 void push(int value) { |
122 DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); | 125 DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); |
123 } | 126 } |
124 | 127 |
125 int pop() { | 128 int pop() { |
126 DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); | 129 DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); |
127 return 0; | 130 return 0; |
128 } | 131 } |
129 | 132 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 #endif | 173 #endif |
171 } | 174 } |
172 | 175 |
173 TEST(ThreadCollisionTest, MTScopedBookCriticalSectionTest) { | 176 TEST(ThreadCollisionTest, MTScopedBookCriticalSectionTest) { |
174 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 177 // Queue with a 5 seconds push execution time, hopefuly the two used threads |
175 // in the test will enter the push at same time. | 178 // in the test will enter the push at same time. |
176 class NonThreadSafeQueue { | 179 class NonThreadSafeQueue { |
177 public: | 180 public: |
178 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 181 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
179 #if !defined(NDEBUG) | 182 #if !defined(NDEBUG) |
180 : push_pop_(asserter) | 183 : push_pop_(asserter) { |
| 184 #else |
| 185 { |
| 186 delete asserter; |
181 #endif | 187 #endif |
182 { } | 188 } |
183 | 189 |
184 void push(int value) { | 190 void push(int value) { |
185 DFAKE_SCOPED_LOCK(push_pop_); | 191 DFAKE_SCOPED_LOCK(push_pop_); |
186 PlatformThread::Sleep(5000); | 192 PlatformThread::Sleep(5000); |
187 } | 193 } |
188 | 194 |
189 int pop() { | 195 int pop() { |
190 DFAKE_SCOPED_LOCK(push_pop_); | 196 DFAKE_SCOPED_LOCK(push_pop_); |
191 return 0; | 197 return 0; |
192 } | 198 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 #endif | 240 #endif |
235 } | 241 } |
236 | 242 |
237 TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { | 243 TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { |
238 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 244 // Queue with a 5 seconds push execution time, hopefuly the two used threads |
239 // in the test will enter the push at same time. | 245 // in the test will enter the push at same time. |
240 class NonThreadSafeQueue { | 246 class NonThreadSafeQueue { |
241 public: | 247 public: |
242 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 248 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
243 #if !defined(NDEBUG) | 249 #if !defined(NDEBUG) |
244 : push_pop_(asserter) | 250 : push_pop_(asserter) { |
| 251 #else |
| 252 { |
| 253 delete asserter; |
245 #endif | 254 #endif |
246 { } | 255 } |
247 | 256 |
248 void push(int value) { | 257 void push(int value) { |
249 DFAKE_SCOPED_LOCK(push_pop_); | 258 DFAKE_SCOPED_LOCK(push_pop_); |
250 PlatformThread::Sleep(5000); | 259 PlatformThread::Sleep(5000); |
251 } | 260 } |
252 | 261 |
253 int pop() { | 262 int pop() { |
254 DFAKE_SCOPED_LOCK(push_pop_); | 263 DFAKE_SCOPED_LOCK(push_pop_); |
255 return 0; | 264 return 0; |
256 } | 265 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 EXPECT_FALSE(local_reporter->fail_state()); | 314 EXPECT_FALSE(local_reporter->fail_state()); |
306 } | 315 } |
307 | 316 |
308 TEST(ThreadCollisionTest, MTSynchedScopedRecursiveBookCriticalSectionTest) { | 317 TEST(ThreadCollisionTest, MTSynchedScopedRecursiveBookCriticalSectionTest) { |
309 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 318 // Queue with a 5 seconds push execution time, hopefuly the two used threads |
310 // in the test will enter the push at same time. | 319 // in the test will enter the push at same time. |
311 class NonThreadSafeQueue { | 320 class NonThreadSafeQueue { |
312 public: | 321 public: |
313 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 322 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
314 #if !defined(NDEBUG) | 323 #if !defined(NDEBUG) |
315 : push_pop_(asserter) | 324 : push_pop_(asserter) { |
| 325 #else |
| 326 { |
| 327 delete asserter; |
316 #endif | 328 #endif |
317 { } | 329 } |
318 | 330 |
319 void push(int) { | 331 void push(int) { |
320 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); | 332 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |
321 bar(); | 333 bar(); |
322 PlatformThread::Sleep(5000); | 334 PlatformThread::Sleep(5000); |
323 } | 335 } |
324 | 336 |
325 int pop() { | 337 int pop() { |
326 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); | 338 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |
327 return 0; | 339 return 0; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b"); | 389 base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b"); |
378 | 390 |
379 thread_a.Start(); | 391 thread_a.Start(); |
380 thread_b.Start(); | 392 thread_b.Start(); |
381 | 393 |
382 thread_a.Join(); | 394 thread_a.Join(); |
383 thread_b.Join(); | 395 thread_b.Join(); |
384 | 396 |
385 EXPECT_FALSE(local_reporter->fail_state()); | 397 EXPECT_FALSE(local_reporter->fail_state()); |
386 } | 398 } |
OLD | NEW |