Closed betzw closed 7 years ago
@c1728p9, oh hey, is this the issue you noted a while back?
Other question out of curiousity, is marking _wloc/_rloc as volatile also a valid solution?
_wloc
/_rloc
are already volatile and this seems not to be sufficient for not making the compiler reorder the instructions.
Ignore me, just triggering CI :)
@c1728p9, oh hey, is this the issue you noted a while back?
Yep. I should have just fixed this when I saw it rather than just reporting it.
Other question out of curiousity, is marking _wloc/_rloc as volatile also a valid solution?
The volatile statement only prevents reordering relative to other volatile statements. Since _buf
is not pointing to a volatile type the access can be re-ordered before or after the increment (as long as the original index value is used). Changing the element type of _buf
to be volatile (and moving the increment out of indexing) would fix this problem, but could degrade performance.
Just to in form you that I have integrated @c1728p9's suggestion.
Thanks! Looks good to me, time for merge
Insert compiler optimization barriers into methods MyBuffer::put() & MyBuffer::get()
This modification is required to force the compiler to increment the read/write location pointers _rloc and _wloc only after having read/written the data from/to the buffer. This happened on my side on a NUCLEO_F401RE + X-NUCLEO-IDW01M1 using GCC_ARM toolchain (version 6.3.1 20170620 (release)).
cc @geky