SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST() [43/59]

SpicesTest::TEST ( Semaphore_test ,
Wait  )

Testing Spices::Semaphore::Wait.

Definition at line 63 of file Semaphore_test.h.

63 {
64
66
68
69 const auto t0 = std::chrono::high_resolution_clock::now();
70
71 std::thread t([&]() {
72 std::this_thread::sleep_for(std::chrono::seconds(1));
73 sem.Sign(1);
74 });
75
76 t.detach();
77
78 // Should not block here.
79 {
80 sem.Wait(0);
81
82 const auto time = std::chrono::high_resolution_clock::now();
83 const float period = std::chrono::duration<float, std::chrono::milliseconds::period>(time - t0).count();
84
85 EXPECT_LE(period, 50);
86 }
87
88 // Should block here.
89 {
90 sem.Wait(1);
91
92 const auto time = std::chrono::high_resolution_clock::now();
93 const float period = std::chrono::duration<float, std::chrono::milliseconds::period>(time - t0).count();
94
95 EXPECT_LE(period, 1050);
96 EXPECT_GE(period, 950);
97 }
98 }
#define SPICESTEST_PROFILE_FUNCTION()
void Sign(int sign)
Sign this semaphore with specific value.
Definition Semaphore.h:34
void Wait(int sign)
Wait this semaphore until it owns equal sign with given.
Definition Semaphore.h:57
std::semaphore Implementation.
Definition Semaphore.h:16

References Spices::semaphore::Sign(), and Spices::semaphore::Wait().