2.6.x chTimeNow() safe without system lock?
Posted: Tue Jul 21, 2015 10:20 pm
Hi Giovanni,
chTimeNow() is a marco returning vtlist.vt_systime.
https://github.com/ChibiOS/ChibiOS/blob ... hvt.h#L216
In its doxygen header it is marked as @api which means it can be used from outside of a system lock zone.
vtlist.vt_systime is incremented here:
https://github.com/ChibiOS/ChibiOS/blob ... hvt.h#L140
But there are architectures where the variable access is not an atomic operation like e.g. AVR.
systime_t of AVR port is uint16_t but AVR registers width is 8 bits and thus more than one instruction is required to read vtlist.vt_systime from memory.
As i understand it, this means chTimeNow() could return a value which is in the middle of being incremented.
https://github.com/ChibiOS/ChibiOS/blob ... ypes.h#L53
Shouldn't there be chTimeNowI() and shouldn't chTimeNow() access vtlist.vt_systime from within a system lock
- at least if access to vtlist.vt_systime is not guaranteed to be atomic?
Thanks for clarification and best regards
Vinz
chTimeNow() is a marco returning vtlist.vt_systime.
https://github.com/ChibiOS/ChibiOS/blob ... hvt.h#L216
In its doxygen header it is marked as @api which means it can be used from outside of a system lock zone.
vtlist.vt_systime is incremented here:
https://github.com/ChibiOS/ChibiOS/blob ... hvt.h#L140
But there are architectures where the variable access is not an atomic operation like e.g. AVR.
systime_t of AVR port is uint16_t but AVR registers width is 8 bits and thus more than one instruction is required to read vtlist.vt_systime from memory.
As i understand it, this means chTimeNow() could return a value which is in the middle of being incremented.
https://github.com/ChibiOS/ChibiOS/blob ... ypes.h#L53
Shouldn't there be chTimeNowI() and shouldn't chTimeNow() access vtlist.vt_systime from within a system lock
- at least if access to vtlist.vt_systime is not guaranteed to be atomic?
Thanks for clarification and best regards
Vinz