Skip to content

Commit

Permalink
[fiber] Guarantee minimum for durations < 1µs
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Aug 9, 2024
1 parent 6e03e09 commit 0fef334
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modm/processing/fiber/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ poll_for(std::chrono::duration<Rep, Period> sleep_duration, Function &&condition
std::chrono::duration<Rep, std::milli>>,
modm::chrono::milli_clock, modm::chrono::micro_clock>;

// Ensure the sleep duration is at least 1 clock tick
const auto clock_sleep_duration(
std::chrono::ceil<typename Clock::duration>(sleep_duration));

const auto start = Clock::now();
do {
modm::this_fiber::yield();
if (std::forward<Function>(condition)()) return true;
}
while((Clock::now() - start) <= sleep_duration);
while((Clock::now() - start) <= clock_sleep_duration);
return false;
}

Expand Down

0 comments on commit 0fef334

Please sign in to comment.