| 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/time.h" | 5 #include "base/time.h" |
| 6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 class WaitableEventSignaler : public PlatformThread::Delegate { | 72 class WaitableEventSignaler : public PlatformThread::Delegate { |
| 73 public: | 73 public: |
| 74 WaitableEventSignaler(double seconds, WaitableEvent* ev) | 74 WaitableEventSignaler(double seconds, WaitableEvent* ev) |
| 75 : seconds_(seconds), | 75 : seconds_(seconds), |
| 76 ev_(ev) { | 76 ev_(ev) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ThreadMain() { | 79 void ThreadMain() { |
| 80 PlatformThread::Sleep(static_cast<int>(seconds_ * 1000)); | 80 PlatformThread::Sleep(TimeDelta::FromSeconds(static_cast<int>(seconds_))); |
| 81 ev_->Signal(); | 81 ev_->Signal(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 const double seconds_; | 85 const double seconds_; |
| 86 WaitableEvent *const ev_; | 86 WaitableEvent *const ev_; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 TEST(WaitableEventTest, WaitMany) { | 89 TEST(WaitableEventTest, WaitMany) { |
| 90 WaitableEvent* ev[5]; | 90 WaitableEvent* ev[5]; |
| 91 for (unsigned i = 0; i < 5; ++i) | 91 for (unsigned i = 0; i < 5; ++i) |
| 92 ev[i] = new WaitableEvent(false, false); | 92 ev[i] = new WaitableEvent(false, false); |
| 93 | 93 |
| 94 WaitableEventSignaler signaler(0.1, ev[2]); | 94 WaitableEventSignaler signaler(0.1, ev[2]); |
| 95 PlatformThreadHandle thread; | 95 PlatformThreadHandle thread; |
| 96 PlatformThread::Create(0, &signaler, &thread); | 96 PlatformThread::Create(0, &signaler, &thread); |
| 97 | 97 |
| 98 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 2u); | 98 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 2u); |
| 99 | 99 |
| 100 PlatformThread::Join(thread); | 100 PlatformThread::Join(thread); |
| 101 | 101 |
| 102 for (unsigned i = 0; i < 5; ++i) | 102 for (unsigned i = 0; i < 5; ++i) |
| 103 delete ev[i]; | 103 delete ev[i]; |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace base | 106 } // namespace base |
| OLD | NEW |