7#include "flutter/fml/synchronization/semaphore.h"
8#include "flutter/fml/thread.h"
9#include "flutter/fml/time/time_point.h"
10#include "gtest/gtest.h"
12TEST(SemaphoreTest, SimpleValidity) {
17TEST(SemaphoreTest, WaitOnZero) {
22TEST(SemaphoreTest, WaitOnZeroSignalThenWait) {
25 std::thread thread([&sem]() { sem.
Signal(); });
31TEST(SemaphoreTest, IndefiniteWait) {
33 constexpr double wait_in_seconds = 0.25;
38 [&sem]() { sem.
Signal(); },
40 ASSERT_TRUE(sem.
Wait());
42 ASSERT_GE(
delta.ToSecondsF(), wait_in_seconds);
A traditional counting semaphore. Waits decrement the counter and Signal increments it.
bool IsValid() const
Check if the underlying semaphore handle could be created. Failure modes are platform specific and ma...
void Signal()
Increment the count by one. Any pending Waits will be resolved at this point.
bool TryWait()
Decrement the counts if it is greater than zero. Returns false if the counter is already at zero.
bool Wait()
Decrements the count and waits indefinitely if the value is less than zero for a Signal.
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static constexpr TimeDelta FromSecondsF(double seconds)
TEST(SemaphoreTest, SimpleValidity)