| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/WaitableEvent.h" | 5 #include "platform/WaitableEvent.h" |
| 6 | 6 |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "platform/heap/SafePoint.h" | 8 #include "platform/heap/SafePoint.h" |
| 9 #include "platform/heap/ThreadState.h" | 9 #include "platform/heap/ThreadState.h" |
| 10 #include "wtf/Optional.h" | 10 #include "wtf/Optional.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 : base::WaitableEvent::InitialState::NOT_SIGNALED)); | 23 : base::WaitableEvent::InitialState::NOT_SIGNALED)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 WaitableEvent::~WaitableEvent() {} | 26 WaitableEvent::~WaitableEvent() {} |
| 27 | 27 |
| 28 void WaitableEvent::reset() { | 28 void WaitableEvent::reset() { |
| 29 m_impl->Reset(); | 29 m_impl->Reset(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void WaitableEvent::wait() { | 32 void WaitableEvent::wait() { |
| 33 if (ThreadState::current()) { | 33 m_impl->Wait(); |
| 34 // We only enter a safe point scope if the thread is attached, ex. never | |
| 35 // during shutdown. | |
| 36 // TODO(esprehn): Why can't SafePointScope do this for us? | |
| 37 SafePointScope scope(BlinkGC::HeapPointersOnStack); | |
| 38 m_impl->Wait(); | |
| 39 } else { | |
| 40 m_impl->Wait(); | |
| 41 } | |
| 42 } | 34 } |
| 43 | 35 |
| 44 void WaitableEvent::signal() { | 36 void WaitableEvent::signal() { |
| 45 m_impl->Signal(); | 37 m_impl->Signal(); |
| 46 } | 38 } |
| 47 | 39 |
| 48 size_t WaitableEvent::waitMultiple(const WTF::Vector<WaitableEvent*>& events) { | 40 size_t WaitableEvent::waitMultiple(const WTF::Vector<WaitableEvent*>& events) { |
| 49 std::vector<base::WaitableEvent*> baseEvents; | 41 std::vector<base::WaitableEvent*> baseEvents; |
| 50 for (size_t i = 0; i < events.size(); ++i) | 42 for (size_t i = 0; i < events.size(); ++i) |
| 51 baseEvents.push_back(events[i]->m_impl.get()); | 43 baseEvents.push_back(events[i]->m_impl.get()); |
| 52 size_t idx = | 44 size_t idx = |
| 53 base::WaitableEvent::WaitMany(baseEvents.data(), baseEvents.size()); | 45 base::WaitableEvent::WaitMany(baseEvents.data(), baseEvents.size()); |
| 54 DCHECK_LT(idx, events.size()); | 46 DCHECK_LT(idx, events.size()); |
| 55 return idx; | 47 return idx; |
| 56 } | 48 } |
| 57 | 49 |
| 58 } // namespace blink | 50 } // namespace blink |
| OLD | NEW |