mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 09:38:42 +00:00
22ed9b3c1e821e55b2fc4163290fd075705c68ec
Copilot review on #15947 flagged that `volatile uint32_t` is not a well-defined concurrent access in the C++ memory model — it prevents the compiler caching/eliding the read, but does not turn a plain cross-thread read/write pair into a defined access. Technically still a formal data race even though aligned 32-bit LDR/STR on ARMv5TE is atomic at the hardware level. Switch the NO_ATOMICS counter reads and writes to GCC's atomic builtins with __ATOMIC_RELAXED: - Readers: __atomic_load_n(&counter, __ATOMIC_RELAXED) - Writers (under lock_): __atomic_store_n(&counter, new_value, __ATOMIC_RELAXED) - Increment/decrement (under lock_): explicit load + compute + __atomic_store_n. Lock_ serialises the load-modify-store against other writers; the atomic ops make the write visible to concurrent readers in the memory model. On ARMv5TE these builtins compile to plain LDR/STR — same codegen as the previous volatile approach, and no libatomic dependency (only RMW builtins like __atomic_fetch_add would need the lib). ATOMICS and SINGLE paths are unchanged.
Description
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Readme
Multiple Licenses
601 MiB
Languages
C++
55.8%
Python
43.6%
C
0.3%
JavaScript
0.2%
