Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
fml::AutoResetWaitableEvent Class Referencefinal

#include <waitable_event.h>

Public Member Functions

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

Detailed Description

Definition at line 28 of file waitable_event.h.

Constructor & Destructor Documentation

◆ AutoResetWaitableEvent()

fml::AutoResetWaitableEvent::AutoResetWaitableEvent ( )
inline

Definition at line 30 of file waitable_event.h.

30{}

◆ ~AutoResetWaitableEvent()

fml::AutoResetWaitableEvent::~AutoResetWaitableEvent ( )
inline

Definition at line 31 of file waitable_event.h.

31{}

Member Function Documentation

◆ IsSignaledForTest()

bool fml::AutoResetWaitableEvent::IsSignaledForTest ( )

Definition at line 120 of file waitable_event.cc.

120 {
121 std::scoped_lock locker(mutex_);
122 return signaled_;
123}

◆ Reset()

void fml::AutoResetWaitableEvent::Reset ( )

Definition at line 67 of file waitable_event.cc.

67 {
68 std::scoped_lock locker(mutex_);
69 signaled_ = false;
70}

◆ Signal()

void fml::AutoResetWaitableEvent::Signal ( )

Definition at line 61 of file waitable_event.cc.

61 {
62 std::scoped_lock locker(mutex_);
63 signaled_ = true;
64 cv_.notify_one();
65}

◆ Wait()

void fml::AutoResetWaitableEvent::Wait ( )

Definition at line 72 of file waitable_event.cc.

72 {
73 std::unique_lock<std::mutex> locker(mutex_);
74 while (!signaled_) {
75 cv_.wait(locker);
76 }
77 signaled_ = false;
78}

◆ WaitWithTimeout()

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

Definition at line 80 of file waitable_event.cc.

80 {
81 std::unique_lock<std::mutex> locker(mutex_);
82
83 if (signaled_) {
84 signaled_ = false;
85 return false;
86 }
87
88 // We may get spurious wakeups.
89 TimeDelta wait_remaining = timeout;
91 while (true) {
93 cv_.wait_for(
94 locker, std::chrono::nanoseconds(wait_remaining.ToNanoseconds()))) {
95 return true; // Definitely timed out.
96 }
97
98 // We may have been awoken.
99 if (signaled_) {
100 break;
101 }
102
103 // Or the wakeup may have been spurious.
105 FML_DCHECK(now >= start);
106 TimeDelta elapsed = now - start;
107 // It's possible that we may have timed out anyway.
108 if (elapsed >= timeout) {
109 return true;
110 }
111
112 // Otherwise, recalculate the amount that we have left to wait.
113 wait_remaining = timeout - elapsed;
114 }
115
116 signaled_ = false;
117 return false;
118}
static TimePoint Now()
Definition: time_point.cc:49
#define FML_DCHECK(condition)
Definition: logging.h:103
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition: timing.h:15
def timeout(deadline, cmd)

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