OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
10 #include "base/threading/thread_collision_warner.h" | 10 #include "base/threading/thread_collision_warner.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Queue with a 5 seconds push execution time, hopefuly the two used threads | 183 // Queue with a 5 seconds push execution time, hopefuly the two used threads |
184 // in the test will enter the push at same time. | 184 // in the test will enter the push at same time. |
185 class NonThreadSafeQueue { | 185 class NonThreadSafeQueue { |
186 public: | 186 public: |
187 explicit NonThreadSafeQueue(base::AsserterBase* asserter) | 187 explicit NonThreadSafeQueue(base::AsserterBase* asserter) |
188 : push_pop_(asserter) { | 188 : push_pop_(asserter) { |
189 } | 189 } |
190 | 190 |
191 void push(int value) { | 191 void push(int value) { |
192 DFAKE_SCOPED_LOCK(push_pop_); | 192 DFAKE_SCOPED_LOCK(push_pop_); |
193 base::PlatformThread::Sleep(5000); | 193 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(5)); |
194 } | 194 } |
195 | 195 |
196 int pop() { | 196 int pop() { |
197 DFAKE_SCOPED_LOCK(push_pop_); | 197 DFAKE_SCOPED_LOCK(push_pop_); |
198 return 0; | 198 return 0; |
199 } | 199 } |
200 | 200 |
201 private: | 201 private: |
202 DFAKE_MUTEX(push_pop_); | 202 DFAKE_MUTEX(push_pop_); |
203 | 203 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Queue with a 2 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 base::PlatformThread::Sleep(2000); | 251 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2)); |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::PlatformThread::Sleep(2000); | 321 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2)); |
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 |