| Index: webrtc/base/criticalsection_unittest.cc
|
| diff --git a/webrtc/base/criticalsection_unittest.cc b/webrtc/base/criticalsection_unittest.cc
|
| index ff4fdef9486f2a19ca83450c9175d205039e55de..85ef20dc409ae0e1bdaca5d476502e6ec5fac5f2 100644
|
| --- a/webrtc/base/criticalsection_unittest.cc
|
| +++ b/webrtc/base/criticalsection_unittest.cc
|
| @@ -14,6 +14,7 @@
|
| #include "webrtc/base/criticalsection.h"
|
| #include "webrtc/base/event.h"
|
| #include "webrtc/base/gunit.h"
|
| +#include "webrtc/base/scoped_ptr.h"
|
| #include "webrtc/base/scopedptrcollection.h"
|
| #include "webrtc/base/thread.h"
|
| #include "webrtc/test/testsupport/gtest_disable.h"
|
| @@ -220,6 +221,28 @@ TEST(AtomicOpsTest, Simple) {
|
| EXPECT_EQ(0, value);
|
| }
|
|
|
| +TEST(AtomicOpsTest, SimplePtr) {
|
| + class Foo {};
|
| + Foo* volatile foo = nullptr;
|
| + scoped_ptr<Foo> a(new Foo());
|
| + scoped_ptr<Foo> b(new Foo());
|
| + // Reading the initial value should work as expected.
|
| + EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == nullptr);
|
| + // Setting using compare and swap should work.
|
| + EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
|
| + &foo, static_cast<Foo*>(nullptr), a.get()) == nullptr);
|
| + EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
|
| + // Setting another value but with the wrong previous pointer should fail
|
| + // (remain a).
|
| + EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
|
| + &foo, static_cast<Foo*>(nullptr), b.get()) == a.get());
|
| + EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
|
| + // Replacing a with b should work.
|
| + EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(&foo, a.get(), b.get()) ==
|
| + a.get());
|
| + EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == b.get());
|
| +}
|
| +
|
| TEST(AtomicOpsTest, Increment) {
|
| // Create and start lots of threads.
|
| AtomicOpRunner<IncrementOp, UniqueValueVerifier> runner(0);
|
|
|