[riot-notifications] [RIOT-OS/RIOT] drivers/pulse_counter: Use C11 atomics & bugfix (#11432)
notifications at github.com
Tue Apr 23 14:45:23 CEST 2019
### Contribution description
- Previously the pulse counter used GCC's built-in functions for atomic memory access. This PR changes this to use C11 atomics instead:
- Use of C11 atomics instead of atomic build-in functions makes the code more portable and readable.
- Previously pulse_counter_reset() did not use an atomic function, so that resets would be racy. (E.g. on the 8-bit AVR platform an 16-bit store is not atomic, unless special care (like using C11 atomics) is taken.)
### Testing procedure
E.g. run `USEMODULE=pulse_counter make` in `examples/saul` and check if everything is still working. But it is very plausible that even non-atomic code would work fine for very long time, as the data race here is very unlikely. Therefore, additional testing should be done:
#### Check if atomics are actually used
E.g. compile `examples/saul` for the Arduino Mega2560 (run `USEMODULE=pulse_counter make BOARD=arduino-mega2560` in `examples/saul`). This 8 bit platform is unable to provide lock-free atomic access to 16 bit of memory and, thus, will rely on the `__atomic*()` set of helper functions to perform the atomic memory accesses. Thus
avr-readelf -s bin/arduino-mega2560/saul.a | grep atomic
should yield references to `__atomic_fetch_add_2`, `__atomic_store_2`, `__atomic_exchange_2`, and `__atomic_load_2`.
A correct compilation should contain lines like this
153: 00000000 0 NOTYPE GLOBAL DEFAULT UND __atomic_fetch_add_2
156: 00000000 0 NOTYPE GLOBAL DEFAULT UND __atomic_store_2
158: 00000000 0 NOTYPE GLOBAL DEFAULT UND __atomic_exchange_2
160: 00000000 0 NOTYPE GLOBAL DEFAULT UND __atomic_load_
### Issues/PRs references
You can view, comment on, or merge this pull request online at:
-- Commit Summary --
* drivers/pulse_counter: Use C11 atomics & bugfix
-- File Changes --
M drivers/include/pulse_counter.h (3)
M drivers/pulse_counter/pulse_counter.c (20)
-- Patch Links --
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the notifications