On 24/06/16 22:59, Jacob Moroni wrote:
Also, on a somewhat related note, I think there may be a bug in the <avr/atomic.h> header, specifically, in the “__iRestore” function which is called to restore the interrupt state after the atomic block is finished. There’s currently a memory barrier after SREG is restored, but I think the barrier should be before in order to ensure that any pending stores are completed _before_ restoring the interrupt state. If the barrier is after, I’m not sure if there’s anything preventing operations on non-volatile variables from being reordered with respect to the restoring of SREG.
It has been a while since I looked at such things in detail, and I don't have the appropriate references conveniently available at the moment. But if I remember correctly, the change to the interrupt status is delayed in hardware for an instruction, so that it is safe to re-enable interrupts (restore the SREG) and then have the memory barrier.
It’s likely that this problem has never been encountered in the field because the common practice is to declare all shared globals as “volatile”, which therefore prevents accesses to them from being reordered with respect to access of SREG, but it seems like a possible issue to me. If you agree, I can submit a bug report or even make the fix myself once I figure out the process of sending in a patch. This is actually my first time participating in any type of collaborative open source project!
_______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-libc-dev