[riot-notifications] [RIOT-OS/RIOT] cpu/esp*: memory clobbers required for irq_* functions (#11571)

Kaspar Schleiser notifications at github.com
Tue May 28 16:20:09 CEST 2019


> Why? If for some code it is necessary to place a barrier, why not be explicit and place the barrier only where it is needed?

The reason is that ```irq_*()``` is used to protect critical sections. The barriers are necessary to prevent the compiler from re-ordering memory orders over the critical section start/end.

Conceived example:

```
void list_add(list, new_node) {
irq_disable();
while (list->next) { list = list->next;}
list->next = new_node;
new_node = NULL;
irq_restore();
```

Without a memory barrier in ```irq_restore()```, the compiler is (theoretically) free to move the store in ```list->next = new_node``` after ```irq_restore()```. 
If it does that, a parallel ```list_add(list, other_node)``` in an ISR or higher priority thread might get scheduled right after ```irq_restore()```, write ```other_node``` at the the same position that then gets overwritten.

A lot of code in RIOT depends on this not happening, thus the need for barriers.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/11571#issuecomment-496537375
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190528/af7e2d7c/attachment.html>


More information about the notifications mailing list