Merge pull request #15113 from kaspar030/fix_ztimer_spin

ztimer: fix ztimer_spin() time_left == duration case
This commit is contained in:
benpicco 2020-09-29 13:00:19 +02:00 committed by GitHub
commit 9970a26277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -456,7 +456,10 @@ void ztimer_sleep(ztimer_clock_t *clock, uint32_t duration);
*/
static inline void ztimer_spin(ztimer_clock_t *clock, uint32_t duration) {
uint32_t end = ztimer_now(clock) + duration;
while ((end - ztimer_now(clock)) < duration) {}
/* Rely on integer overflow. `end - now` will be smaller than `duration`,
* counting down, until it underflows to UINT32_MAX. Loop ends then. */
while ((end - ztimer_now(clock)) <= duration) {}
}
/**