xtimer: Handle overflows in xtimer_spin()#4183
Conversation
|
Doesn't modulo 2**32 make this safe for all sane values of offset? An overflow would give this sequence of comparisons (start = 0xFFFFFFFE): (0xFFFFFFFF - 0xFFFFFFFE) = 1, (0x0 - 0xFFFFFFFE) = 2, (0x1 - 0xFFFFFFFE) = 3 So the substraction always yields the nr of ticks since start. |
|
hmm, you have a point. I think this change needs further review. I still believe there is an issue with less-than-32-bit-wide timers though.. |
|
@gebart could you rebase this to master to make the diff a little bit more clear? |
2a08a8f to
1e1e047
Compare
|
@cgundogan, rebased. |
sys/include/xtimer.h
Outdated
There was a problem hiding this comment.
no, because then if the low level timer has not yet incremented since the start tick then we will immediately jump out of the spin.
1e1e047 to
745dcfc
Compare
|
I rewrote this based on the discussion above. To me it seems like this should work for less than 32 bit wide hardware timers as well. What do you think @cgundogan, @kaspar030? |
745dcfc to
14cc40a
Compare
|
rebased on latest master |
|
@kaspar030, ping! |
|
@kaspar030 ping OK to squash? |
|
Yes, looks good! ACK. |
14cc40a to
d95e7a3
Compare
|
rebased, squashed |
|
Getting failures from a Doxygen warning in an unrelated part of the file. I piggybacked one Doxygen fix but I will refactor this file soon-ish so I don't want to spend effort documenting stuff that I haven't touched in this PR. |
xtimer: Handle overflows in xtimer_spin()
(This is based on #4181)This PR fixes a potential problem with xtimer_spin where xtimer_spin will exit early if we are spinning across an overflow boundary of the underlying hardware timer.