mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 16:25:50 +00:00
Compare commits
1 Commits
document_t
...
frame_help
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88717ac1f5 |
@@ -84,9 +84,7 @@ class APIFrameHelper {
|
||||
public:
|
||||
APIFrameHelper() = default;
|
||||
explicit APIFrameHelper(std::unique_ptr<socket::Socket> socket, const ClientInfo *client_info)
|
||||
: socket_owned_(std::move(socket)), client_info_(client_info) {
|
||||
socket_ = socket_owned_.get();
|
||||
}
|
||||
: socket_(std::move(socket)), client_info_(client_info) {}
|
||||
virtual ~APIFrameHelper() = default;
|
||||
virtual APIError init() = 0;
|
||||
virtual APIError loop();
|
||||
@@ -149,9 +147,8 @@ class APIFrameHelper {
|
||||
APIError write_raw_(const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector<uint8_t> &tx_buf,
|
||||
const std::string &info, StateEnum &state, StateEnum failed_state);
|
||||
|
||||
// Pointers first (4 bytes each)
|
||||
socket::Socket *socket_{nullptr};
|
||||
std::unique_ptr<socket::Socket> socket_owned_;
|
||||
// Socket ownership (4 bytes on 32-bit, 8 bytes on 64-bit)
|
||||
std::unique_ptr<socket::Socket> socket_;
|
||||
|
||||
// Common state enum for all frame helpers
|
||||
// Note: Not all states are used by all implementations
|
||||
|
||||
@@ -261,10 +261,6 @@ async def component_to_code(config):
|
||||
cg.add_build_flag(f"-DUSE_LIBRETINY_VARIANT_{config[CONF_FAMILY]}")
|
||||
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
||||
cg.add_define("ESPHOME_VARIANT", FAMILY_FRIENDLY[config[CONF_FAMILY]])
|
||||
# LibreTiny uses MULTI_NO_ATOMICS because platforms like BK7231N (ARM968E-S) lack
|
||||
# exclusive load/store (no LDREX/STREX). std::atomic RMW operations require libatomic,
|
||||
# which is not linked to save flash (4-8KB). Even if linked, libatomic would use locks
|
||||
# (ATOMIC_INT_LOCK_FREE=1), so explicit FreeRTOS mutexes are simpler and equivalent.
|
||||
cg.add_define(ThreadModel.MULTI_NO_ATOMICS)
|
||||
|
||||
# force using arduino framework
|
||||
|
||||
@@ -36,30 +36,7 @@ class Framework(StrEnum):
|
||||
|
||||
|
||||
class ThreadModel(StrEnum):
|
||||
"""Threading model identifiers for ESPHome scheduler.
|
||||
|
||||
ESPHome currently uses three threading models based on platform capabilities:
|
||||
|
||||
SINGLE:
|
||||
- Single-threaded platforms (ESP8266, RP2040)
|
||||
- No RTOS task switching
|
||||
- No concurrent access to scheduler data structures
|
||||
- No atomics or locks required
|
||||
- Minimal overhead
|
||||
|
||||
MULTI_NO_ATOMICS:
|
||||
- Multi-threaded platforms without hardware atomic RMW support (e.g. LibreTiny BK7231N)
|
||||
- Uses FreeRTOS or another RTOS with multiple tasks
|
||||
- CPU lacks exclusive load/store instructions (ARM968E-S has no LDREX/STREX)
|
||||
- std::atomic cannot provide lock-free RMW; libatomic is avoided to save flash (4–8 KB)
|
||||
- Scheduler uses explicit FreeRTOS mutexes for synchronization
|
||||
|
||||
MULTI_ATOMICS:
|
||||
- Multi-threaded platforms with hardware atomic RMW support (ESP32, Cortex-M, Host)
|
||||
- CPU provides native atomic instructions (ESP32 S32C1I, ARM LDREX/STREX)
|
||||
- std::atomic is used for lock-free synchronization
|
||||
- Reduced contention and better performance
|
||||
"""
|
||||
"""Threading model identifiers for ESPHome scheduler."""
|
||||
|
||||
SINGLE = "ESPHOME_THREAD_SINGLE"
|
||||
MULTI_NO_ATOMICS = "ESPHOME_THREAD_MULTI_NO_ATOMICS"
|
||||
|
||||
Reference in New Issue
Block a user