Flutter Engine
fml::ManualResetWaitableEvent Class Referencefinal

#include <waitable_event.h>

Public Member Functions

 ManualResetWaitableEvent ()
 
 ~ManualResetWaitableEvent ()
 
void Reset ()
 
void Signal ()
 
void Wait ()
 
bool WaitWithTimeout (TimeDelta timeout)
 
bool IsSignaledForTest ()
 

Detailed Description

Definition at line 80 of file waitable_event.h.

Constructor & Destructor Documentation

◆ ManualResetWaitableEvent()

fml::ManualResetWaitableEvent::ManualResetWaitableEvent ( )
inline

Definition at line 82 of file waitable_event.h.

82 {}

◆ ~ManualResetWaitableEvent()

Member Function Documentation

◆ IsSignaledForTest()

bool fml::ManualResetWaitableEvent::IsSignaledForTest ( )

Definition at line 171 of file waitable_event.cc.

171  {
172  std::scoped_lock locker(mutex_);
173  return signaled_;
174 }

◆ Reset()

void fml::ManualResetWaitableEvent::Reset ( )

Definition at line 134 of file waitable_event.cc.

134  {
135  std::scoped_lock locker(mutex_);
136  signaled_ = false;
137 }

◆ Signal()

void fml::ManualResetWaitableEvent::Signal ( )

Definition at line 127 of file waitable_event.cc.

Referenced by fml::CountDownLatch::CountDown(), fml::CountDownLatch::CountDownLatch(), and flutter::PlatformView::NotifyCreated().

127  {
128  std::scoped_lock locker(mutex_);
129  signaled_ = true;
130  signal_id_++;
131  cv_.notify_all();
132 }

◆ Wait()

void fml::ManualResetWaitableEvent::Wait ( )

Definition at line 139 of file waitable_event.cc.

Referenced by flutter::PlatformView::NotifyCreated(), and fml::CountDownLatch::Wait().

139  {
140  std::unique_lock<std::mutex> locker(mutex_);
141 
142  if (signaled_) {
143  return;
144  }
145 
146  auto last_signal_id = signal_id_;
147  do {
148  cv_.wait(locker);
149  } while (signal_id_ == last_signal_id);
150 }

◆ WaitWithTimeout()

bool fml::ManualResetWaitableEvent::WaitWithTimeout ( TimeDelta  timeout)

Definition at line 152 of file waitable_event.cc.

References FML_DCHECK, and fml::WaitWithTimeoutImpl().

152  {
153  std::unique_lock<std::mutex> locker(mutex_);
154 
155  auto last_signal_id = signal_id_;
156  // Disable thread-safety analysis for the lambda: We could annotate it with
157  // |FML_EXCLUSIVE_LOCKS_REQUIRED(mutex_)|, but then the analyzer currently
158  // isn't able to figure out that |WaitWithTimeoutImpl()| calls it while
159  // holding |mutex_|.
160  bool rv = WaitWithTimeoutImpl(
161  &locker, &cv_,
162  [this, last_signal_id]() {
163  // Also check |signaled_| in case we're already signaled.
164  return signaled_ || signal_id_ != last_signal_id;
165  },
166  timeout);
167  FML_DCHECK(rv || signaled_ || signal_id_ != last_signal_id);
168  return rv;
169 }
#define FML_DCHECK(condition)
Definition: logging.h:86
bool WaitWithTimeoutImpl(std::unique_lock< std::mutex > *locker, std::condition_variable *cv, ConditionFn condition, TimeDelta timeout)

The documentation for this class was generated from the following files: