Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
semaphore_unittest.cc File Reference
#include <thread>
#include "flutter/fml/synchronization/semaphore.h"
#include "flutter/fml/thread.h"
#include "flutter/fml/time/time_point.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (SemaphoreTest, SimpleValidity)
 
 TEST (SemaphoreTest, WaitOnZero)
 
 TEST (SemaphoreTest, WaitOnZeroSignalThenWait)
 
 TEST (SemaphoreTest, IndefiniteWait)
 

Function Documentation

◆ TEST() [1/4]

TEST ( SemaphoreTest  ,
IndefiniteWait   
)

Definition at line 31 of file semaphore_unittest.cc.

31 {
33 constexpr double wait_in_seconds = 0.25;
34 fml::Semaphore sem(0);
35 ASSERT_TRUE(sem.IsValid());
36 fml::Thread signaller("signaller_thread");
37 signaller.GetTaskRunner()->PostTaskForTime(
38 [&sem]() { sem.Signal(); },
39 start + fml::TimeDelta::FromSecondsF(wait_in_seconds));
40 ASSERT_TRUE(sem.Wait());
42 ASSERT_GE(delta.ToSecondsF(), wait_in_seconds);
43 signaller.Join();
44}
A traditional counting semaphore. Waits decrement the counter and Signal increments it.
Definition semaphore.h:26
static constexpr TimeDelta FromSecondsF(double seconds)
Definition time_delta.h:53
static TimePoint Now()
Definition time_point.cc:49

◆ TEST() [2/4]

TEST ( SemaphoreTest  ,
SimpleValidity   
)

Definition at line 12 of file semaphore_unittest.cc.

12 {
13 fml::Semaphore sem(100);
14 ASSERT_TRUE(sem.IsValid());
15}

◆ TEST() [3/4]

TEST ( SemaphoreTest  ,
WaitOnZero   
)

Definition at line 17 of file semaphore_unittest.cc.

17 {
18 fml::Semaphore sem(0);
19 ASSERT_FALSE(sem.TryWait());
20}

◆ TEST() [4/4]

TEST ( SemaphoreTest  ,
WaitOnZeroSignalThenWait   
)

Definition at line 22 of file semaphore_unittest.cc.

22 {
23 fml::Semaphore sem(0);
24 ASSERT_FALSE(sem.TryWait());
25 std::thread thread([&sem]() { sem.Signal(); });
26 thread.join();
27 ASSERT_TRUE(sem.TryWait());
28 ASSERT_FALSE(sem.TryWait());
29}