| 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/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/simple_thread.h" | 9 #include "base/simple_thread.h" |
| 10 #include "base/thread_collision_warner.h" | 10 #include "base/thread_collision_warner.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 thread_a.Start(); | 231 thread_a.Start(); |
| 232 thread_b.Start(); | 232 thread_b.Start(); |
| 233 | 233 |
| 234 thread_a.Join(); | 234 thread_a.Join(); |
| 235 thread_b.Join(); | 235 thread_b.Join(); |
| 236 | 236 |
| 237 EXPECT_NDEBUG_FALSE_DEBUG_TRUE(local_reporter->fail_state()); | 237 EXPECT_NDEBUG_FALSE_DEBUG_TRUE(local_reporter->fail_state()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { | 240 TEST(ThreadCollisionTest, MTSynchedScopedBookCriticalSectionTest) { |
| 241 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 241 // Queue with a 2 seconds push execution time, hopefuly the two used threads |
| 242 // in the test will enter the push at same time. | 242 // in the test will enter the push at same time. |
| 243 class NonThreadSafeQueue { | 243 class NonThreadSafeQueue { |
| 244 public: | 244 public: |
| 245 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 245 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
| 246 : push_pop_(asserter) { | 246 : push_pop_(asserter) { |
| 247 } | 247 } |
| 248 | 248 |
| 249 void push(int value) { | 249 void push(int value) { |
| 250 DFAKE_SCOPED_LOCK(push_pop_); | 250 DFAKE_SCOPED_LOCK(push_pop_); |
| 251 PlatformThread::Sleep(5000); | 251 PlatformThread::Sleep(2000); |
| 252 } | 252 } |
| 253 | 253 |
| 254 int pop() { | 254 int pop() { |
| 255 DFAKE_SCOPED_LOCK(push_pop_); | 255 DFAKE_SCOPED_LOCK(push_pop_); |
| 256 return 0; | 256 return 0; |
| 257 } | 257 } |
| 258 | 258 |
| 259 private: | 259 private: |
| 260 DFAKE_MUTEX(push_pop_); | 260 DFAKE_MUTEX(push_pop_); |
| 261 | 261 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 thread_a.Start(); | 300 thread_a.Start(); |
| 301 thread_b.Start(); | 301 thread_b.Start(); |
| 302 | 302 |
| 303 thread_a.Join(); | 303 thread_a.Join(); |
| 304 thread_b.Join(); | 304 thread_b.Join(); |
| 305 | 305 |
| 306 EXPECT_FALSE(local_reporter->fail_state()); | 306 EXPECT_FALSE(local_reporter->fail_state()); |
| 307 } | 307 } |
| 308 | 308 |
| 309 TEST(ThreadCollisionTest, MTSynchedScopedRecursiveBookCriticalSectionTest) { | 309 TEST(ThreadCollisionTest, MTSynchedScopedRecursiveBookCriticalSectionTest) { |
| 310 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 310 // Queue with a 2 seconds push execution time, hopefuly the two used threads |
| 311 // in the test will enter the push at same time. | 311 // in the test will enter the push at same time. |
| 312 class NonThreadSafeQueue { | 312 class NonThreadSafeQueue { |
| 313 public: | 313 public: |
| 314 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 314 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
| 315 : push_pop_(asserter) { | 315 : push_pop_(asserter) { |
| 316 } | 316 } |
| 317 | 317 |
| 318 void push(int) { | 318 void push(int) { |
| 319 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); | 319 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |
| 320 bar(); | 320 bar(); |
| 321 PlatformThread::Sleep(5000); | 321 PlatformThread::Sleep(2000); |
| 322 } | 322 } |
| 323 | 323 |
| 324 int pop() { | 324 int pop() { |
| 325 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); | 325 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |
| 326 return 0; | 326 return 0; |
| 327 } | 327 } |
| 328 | 328 |
| 329 void bar() { | 329 void bar() { |
| 330 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); | 330 DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); |
| 331 } | 331 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b"); | 376 base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b"); |
| 377 | 377 |
| 378 thread_a.Start(); | 378 thread_a.Start(); |
| 379 thread_b.Start(); | 379 thread_b.Start(); |
| 380 | 380 |
| 381 thread_a.Join(); | 381 thread_a.Join(); |
| 382 thread_b.Join(); | 382 thread_b.Join(); |
| 383 | 383 |
| 384 EXPECT_FALSE(local_reporter->fail_state()); | 384 EXPECT_FALSE(local_reporter->fail_state()); |
| 385 } | 385 } |
| OLD | NEW |