OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 LockRunner<CriticalSectionLock> runner; | 299 LockRunner<CriticalSectionLock> runner; |
300 ScopedPtrCollection<Thread> threads; | 300 ScopedPtrCollection<Thread> threads; |
301 StartThreads(&threads, &runner); | 301 StartThreads(&threads, &runner); |
302 runner.SetExpectedThreadCount(kNumThreads); | 302 runner.SetExpectedThreadCount(kNumThreads); |
303 | 303 |
304 // Release the hounds! | 304 // Release the hounds! |
305 EXPECT_TRUE(runner.Run()); | 305 EXPECT_TRUE(runner.Run()); |
306 EXPECT_EQ(0, runner.shared_value()); | 306 EXPECT_EQ(0, runner.shared_value()); |
307 } | 307 } |
308 | 308 |
309 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | |
310 TEST(CriticalSectionTest, IsLocked) { | |
311 // Simple single-threaded test of IsLocked. | |
312 CriticalSection cs; | |
313 EXPECT_FALSE(cs.IsLocked()); | |
314 cs.Enter(); | |
315 EXPECT_TRUE(cs.IsLocked()); | |
316 cs.Leave(); | |
317 EXPECT_FALSE(cs.IsLocked()); | |
318 if (!cs.TryEnter()) | |
319 FAIL(); | |
320 EXPECT_TRUE(cs.IsLocked()); | |
321 cs.Leave(); | |
322 EXPECT_FALSE(cs.IsLocked()); | |
323 } | |
324 #endif | |
325 | |
326 class PerfTestData { | 309 class PerfTestData { |
327 public: | 310 public: |
328 PerfTestData(int expected_count, Event* event) | 311 PerfTestData(int expected_count, Event* event) |
329 : cache_line_barrier_1_(), cache_line_barrier_2_(), | 312 : cache_line_barrier_1_(), cache_line_barrier_2_(), |
330 expected_count_(expected_count), event_(event) { | 313 expected_count_(expected_count), event_(event) { |
331 cache_line_barrier_1_[0]++; // Avoid 'is not used'. | 314 cache_line_barrier_1_[0]++; // Avoid 'is not used'. |
332 cache_line_barrier_2_[0]++; // Avoid 'is not used'. | 315 cache_line_barrier_2_[0]++; // Avoid 'is not used'. |
333 } | 316 } |
334 ~PerfTestData() {} | 317 ~PerfTestData() {} |
335 | 318 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 for (auto& t : threads) | 405 for (auto& t : threads) |
423 t.Start(&test_data, kThreadRepeats, 1); | 406 t.Start(&test_data, kThreadRepeats, 1); |
424 | 407 |
425 event.Wait(Event::kForever); | 408 event.Wait(Event::kForever); |
426 | 409 |
427 for (auto& t : threads) | 410 for (auto& t : threads) |
428 t.Stop(); | 411 t.Stop(); |
429 } | 412 } |
430 | 413 |
431 } // namespace rtc | 414 } // namespace rtc |
OLD | NEW |