| 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/synchronization/atomic_flag.h" | 5 #include "base/synchronization/atomic_flag.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/gtest_util.h" | 11 #include "base/test/gtest_util.h" |
| 12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 void ExpectSetFlagDeath(AtomicFlag* flag) { | 21 void ExpectSetFlagDeath(AtomicFlag* flag) { |
| 22 ASSERT_TRUE(flag); | 22 ASSERT_TRUE(flag); |
| 23 EXPECT_DCHECK_DEATH(flag->Set(), ""); | 23 EXPECT_DCHECK_DEATH(flag->Set()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Busy waits (to explicitly avoid using synchronization constructs that would | 26 // Busy waits (to explicitly avoid using synchronization constructs that would |
| 27 // defeat the purpose of testing atomics) until |tested_flag| is set and then | 27 // defeat the purpose of testing atomics) until |tested_flag| is set and then |
| 28 // verifies that non-atomic |*expected_after_flag| is true and sets |*done_flag| | 28 // verifies that non-atomic |*expected_after_flag| is true and sets |*done_flag| |
| 29 // before returning if it's non-null. | 29 // before returning if it's non-null. |
| 30 void BusyWaitUntilFlagIsSet(AtomicFlag* tested_flag, bool* expected_after_flag, | 30 void BusyWaitUntilFlagIsSet(AtomicFlag* tested_flag, bool* expected_after_flag, |
| 31 AtomicFlag* done_flag) { | 31 AtomicFlag* done_flag) { |
| 32 while (!tested_flag->IsSet()) | 32 while (!tested_flag->IsSet()) |
| 33 PlatformThread::YieldCurrentThread(); | 33 PlatformThread::YieldCurrentThread(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 Thread t("AtomicFlagTest.SetOnDifferentThreadDeathTest"); | 122 Thread t("AtomicFlagTest.SetOnDifferentThreadDeathTest"); |
| 123 ASSERT_TRUE(t.Start()); | 123 ASSERT_TRUE(t.Start()); |
| 124 EXPECT_TRUE(t.WaitUntilThreadStarted()); | 124 EXPECT_TRUE(t.WaitUntilThreadStarted()); |
| 125 | 125 |
| 126 AtomicFlag flag; | 126 AtomicFlag flag; |
| 127 flag.Set(); | 127 flag.Set(); |
| 128 t.task_runner()->PostTask(FROM_HERE, Bind(&ExpectSetFlagDeath, &flag)); | 128 t.task_runner()->PostTask(FROM_HERE, Bind(&ExpectSetFlagDeath, &flag)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace base | 131 } // namespace base |
| OLD | NEW |