MCPcopy Create free account
hub / github.com/FastLED/FastLED / wait_for_condition

Function wait_for_condition

tests/fl/stl/isr.cpp:31–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29// Returns true if condition met, false if timeout
30template<typename Predicate>
31static bool wait_for_condition(Predicate pred, std::chrono::milliseconds timeout) { // okay std namespace
32 if (pred()) {
33 return true; // Already satisfied
34 }
35
36 // Get access to the test synchronization primitives from the timer manager
37 auto& manager = fl::isr::TimerThreadManager::instance();
38 fl::unique_lock<fl::mutex> lock(manager.get_test_sync_mutex());
39
40 auto deadline = std::chrono::steady_clock::now() + timeout; // okay std namespace
41
42 while (!pred()) {
43 auto now = std::chrono::steady_clock::now(); // okay std namespace
44 if (now >= deadline) {
45 return false; // Timeout
46 }
47
48 // Wait on condition variable with remaining timeout
49 // This will be notified whenever an ISR executes
50 auto remaining = std::chrono::duration_cast<std::chrono::milliseconds>(deadline - now); // okay std namespace
51 manager.get_test_sync_cv().wait_for(lock, remaining);
52 }
53
54 return true; // Condition met
55}
56
57// =============================================================================
58// Test Handlers

Callers 1

FL_TEST_FILEFunction · 0.85

Calls 1

wait_forMethod · 0.45

Tested by

no test coverage detected