1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-19 16:25:50 +00:00

[core] Document threading model rationale in ThreadModel enum

This commit is contained in:
J. Nick Koston
2025-11-18 14:03:04 -06:00
parent 863bd2302a
commit c156dbc6d6

View File

@@ -38,25 +38,27 @@ class Framework(StrEnum):
class ThreadModel(StrEnum): class ThreadModel(StrEnum):
"""Threading model identifiers for ESPHome scheduler. """Threading model identifiers for ESPHome scheduler.
ESPHome supports three threading models based on platform capabilities: ESPHome currently uses three threading models based on platform capabilities:
SINGLE: Single-threaded platforms (ESP8266, RP2040) SINGLE:
- No FreeRTOS or other RTOS - Single-threaded platforms (ESP8266, RP2040)
- No RTOS task switching
- No concurrent access to scheduler data structures - No concurrent access to scheduler data structures
- No atomics or locks needed - No atomics or locks required
- Minimal overhead - Minimal overhead
MULTI_NO_ATOMICS: Multi-threaded platforms without hardware atomic support (LibreTiny) MULTI_NO_ATOMICS:
- Uses FreeRTOS or other RTOS with multiple tasks - Multi-threaded platforms without hardware atomic RMW support (e.g. LibreTiny BK7231N)
- CPU lacks atomic instructions (e.g., ARM968E-S has no LDREX/STREX) - Uses FreeRTOS or another RTOS with multiple tasks
- libatomic is not linked (would add 4-8KB flash overhead) - CPU lacks exclusive load/store instructions (ARM968E-S has no LDREX/STREX)
- Uses explicit FreeRTOS mutex locking for synchronization - std::atomic cannot provide lock-free RMW; libatomic is avoided to save flash (48 KB)
- Scheduler uses explicit FreeRTOS mutexes for synchronization
MULTI_ATOMICS: Multi-threaded platforms with hardware atomic support (ESP32, Host) MULTI_ATOMICS:
- Uses FreeRTOS or other RTOS with multiple tasks - Multi-threaded platforms with hardware atomic RMW support (ESP32, Cortex-M, Host)
- CPU has native atomic instructions (e.g., ESP32 has S32C1I, ARM Cortex has LDREX/STREX) - CPU provides native atomic instructions (ESP32 S32C1I, ARM LDREX/STREX)
- Uses std::atomic for lock-free synchronization - std::atomic is used for lock-free synchronization
- Better performance through reduced lock contention - Reduced contention and better performance
""" """
SINGLE = "ESPHOME_THREAD_SINGLE" SINGLE = "ESPHOME_THREAD_SINGLE"