| 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 |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "webrtc/base/arraysize.h" | 15 #include "webrtc/base/arraysize.h" |
| 15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 17 #include "webrtc/base/event.h" | 18 #include "webrtc/base/event.h" |
| 18 #include "webrtc/base/gunit.h" | 19 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/base/platform_thread.h" | 20 #include "webrtc/base/platform_thread.h" |
| 20 #include "webrtc/base/scoped_ptr.h" | |
| 21 #include "webrtc/base/scopedptrcollection.h" | 21 #include "webrtc/base/scopedptrcollection.h" |
| 22 #include "webrtc/base/thread.h" | 22 #include "webrtc/base/thread.h" |
| 23 | 23 |
| 24 namespace rtc { | 24 namespace rtc { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int kLongTime = 10000; // 10 seconds | 28 const int kLongTime = 10000; // 10 seconds |
| 29 const int kNumThreads = 16; | 29 const int kNumThreads = 16; |
| 30 const int kOperationsToRun = 1000; | 30 const int kOperationsToRun = 1000; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 EXPECT_EQ(2, value); | 219 EXPECT_EQ(2, value); |
| 220 EXPECT_EQ(1, AtomicOps::Decrement(&value)); | 220 EXPECT_EQ(1, AtomicOps::Decrement(&value)); |
| 221 EXPECT_EQ(1, value); | 221 EXPECT_EQ(1, value); |
| 222 EXPECT_EQ(0, AtomicOps::Decrement(&value)); | 222 EXPECT_EQ(0, AtomicOps::Decrement(&value)); |
| 223 EXPECT_EQ(0, value); | 223 EXPECT_EQ(0, value); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST(AtomicOpsTest, SimplePtr) { | 226 TEST(AtomicOpsTest, SimplePtr) { |
| 227 class Foo {}; | 227 class Foo {}; |
| 228 Foo* volatile foo = nullptr; | 228 Foo* volatile foo = nullptr; |
| 229 scoped_ptr<Foo> a(new Foo()); | 229 std::unique_ptr<Foo> a(new Foo()); |
| 230 scoped_ptr<Foo> b(new Foo()); | 230 std::unique_ptr<Foo> b(new Foo()); |
| 231 // Reading the initial value should work as expected. | 231 // Reading the initial value should work as expected. |
| 232 EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == nullptr); | 232 EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == nullptr); |
| 233 // Setting using compare and swap should work. | 233 // Setting using compare and swap should work. |
| 234 EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr( | 234 EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr( |
| 235 &foo, static_cast<Foo*>(nullptr), a.get()) == nullptr); | 235 &foo, static_cast<Foo*>(nullptr), a.get()) == nullptr); |
| 236 EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get()); | 236 EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get()); |
| 237 // Setting another value but with the wrong previous pointer should fail | 237 // Setting another value but with the wrong previous pointer should fail |
| 238 // (remain a). | 238 // (remain a). |
| 239 EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr( | 239 EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr( |
| 240 &foo, static_cast<Foo*>(nullptr), b.get()) == a.get()); | 240 &foo, static_cast<Foo*>(nullptr), b.get()) == a.get()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 for (auto& t : threads) | 422 for (auto& t : threads) |
| 423 t.Start(&test_data, kThreadRepeats, 1); | 423 t.Start(&test_data, kThreadRepeats, 1); |
| 424 | 424 |
| 425 event.Wait(Event::kForever); | 425 event.Wait(Event::kForever); |
| 426 | 426 |
| 427 for (auto& t : threads) | 427 for (auto& t : threads) |
| 428 t.Stop(); | 428 t.Stop(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 } // namespace rtc | 431 } // namespace rtc |
| OLD | NEW |