| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 delete ev[i]; | 71 delete ev[i]; |
| 72 } | 72 } |
| 73 | 73 |
| 74 class WaitableEventSignaler : public PlatformThread::Delegate { | 74 class WaitableEventSignaler : public PlatformThread::Delegate { |
| 75 public: | 75 public: |
| 76 WaitableEventSignaler(double seconds, WaitableEvent* ev) | 76 WaitableEventSignaler(double seconds, WaitableEvent* ev) |
| 77 : seconds_(seconds), | 77 : seconds_(seconds), |
| 78 ev_(ev) { | 78 ev_(ev) { |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual void ThreadMain() OVERRIDE { | 81 virtual void ThreadMain() override { |
| 82 PlatformThread::Sleep(TimeDelta::FromSecondsD(seconds_)); | 82 PlatformThread::Sleep(TimeDelta::FromSecondsD(seconds_)); |
| 83 ev_->Signal(); | 83 ev_->Signal(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 const double seconds_; | 87 const double seconds_; |
| 88 WaitableEvent *const ev_; | 88 WaitableEvent *const ev_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 TEST(WaitableEventTest, WaitAndDelete) { | 91 TEST(WaitableEventTest, WaitAndDelete) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 121 size_t index = WaitableEvent::WaitMany(ev, 5); | 121 size_t index = WaitableEvent::WaitMany(ev, 5); |
| 122 | 122 |
| 123 for (unsigned i = 0; i < 5; ++i) | 123 for (unsigned i = 0; i < 5; ++i) |
| 124 delete ev[i]; | 124 delete ev[i]; |
| 125 | 125 |
| 126 PlatformThread::Join(thread); | 126 PlatformThread::Join(thread); |
| 127 EXPECT_EQ(2u, index); | 127 EXPECT_EQ(2u, index); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace base | 130 } // namespace base |
| OLD | NEW |