| 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" |
| 9 #include "platform/heap/ThreadState.h" |
| 10 #include "wtf/Optional.h" |
| 8 #include "wtf/PtrUtil.h" | 11 #include "wtf/PtrUtil.h" |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 namespace blink { | 14 namespace blink { |
| 12 | 15 |
| 13 WaitableEvent::WaitableEvent(ResetPolicy policy, InitialState state) | 16 WaitableEvent::WaitableEvent(ResetPolicy policy, InitialState state) |
| 14 { | 17 { |
| 15 m_impl = wrapUnique(new base::WaitableEvent( | 18 m_impl = wrapUnique(new base::WaitableEvent( |
| 16 policy == ResetPolicy::Manual | 19 policy == ResetPolicy::Manual |
| 17 ? base::WaitableEvent::ResetPolicy::MANUAL | 20 ? base::WaitableEvent::ResetPolicy::MANUAL |
| 18 : base::WaitableEvent::ResetPolicy::AUTOMATIC, | 21 : base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 19 state == InitialState::Signaled | 22 state == InitialState::Signaled |
| 20 ? base::WaitableEvent::InitialState::SIGNALED | 23 ? base::WaitableEvent::InitialState::SIGNALED |
| 21 : base::WaitableEvent::InitialState::NOT_SIGNALED)); | 24 : base::WaitableEvent::InitialState::NOT_SIGNALED)); |
| 22 } | 25 } |
| 23 | 26 |
| 24 WaitableEvent::~WaitableEvent() {} | 27 WaitableEvent::~WaitableEvent() {} |
| 25 | 28 |
| 26 void WaitableEvent::reset() | 29 void WaitableEvent::reset() |
| 27 { | 30 { |
| 28 m_impl->Reset(); | 31 m_impl->Reset(); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void WaitableEvent::wait() | 34 void WaitableEvent::wait() |
| 32 { | 35 { |
| 33 m_impl->Wait(); | 36 if (ThreadState::current()) { |
| 37 // We only enter a safe point scope if the thread is attached, ex. never |
| 38 // during shutdown. |
| 39 // TODO(esprehn): Why can't SafePointScope do this for us? |
| 40 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 41 m_impl->Wait(); |
| 42 } else { |
| 43 m_impl->Wait(); |
| 44 } |
| 34 } | 45 } |
| 35 | 46 |
| 36 void WaitableEvent::signal() | 47 void WaitableEvent::signal() |
| 37 { | 48 { |
| 38 m_impl->Signal(); | 49 m_impl->Signal(); |
| 39 } | 50 } |
| 40 | 51 |
| 41 size_t WaitableEvent::waitMultiple(const WTF::Vector<WaitableEvent*>& events) | 52 size_t WaitableEvent::waitMultiple(const WTF::Vector<WaitableEvent*>& events) |
| 42 { | 53 { |
| 43 std::vector<base::WaitableEvent*> baseEvents; | 54 std::vector<base::WaitableEvent*> baseEvents; |
| 44 for (size_t i = 0; i < events.size(); ++i) | 55 for (size_t i = 0; i < events.size(); ++i) |
| 45 baseEvents.push_back(events[i]->m_impl.get()); | 56 baseEvents.push_back(events[i]->m_impl.get()); |
| 46 size_t idx = base::WaitableEvent::WaitMany(baseEvents.data(), baseEvents.siz
e()); | 57 size_t idx = base::WaitableEvent::WaitMany(baseEvents.data(), baseEvents.siz
e()); |
| 47 DCHECK_LT(idx, events.size()); | 58 DCHECK_LT(idx, events.size()); |
| 48 return idx; | 59 return idx; |
| 49 } | 60 } |
| 50 | 61 |
| 51 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |