mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 10:36:01 +00:00
Merge remote-tracking branch 'origin/inline-mutex-single-threaded' into integration
This commit is contained in:
@@ -20,12 +20,6 @@ bool random_bytes(uint8_t *data, size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
|
||||
Mutex::~Mutex() {}
|
||||
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
|
||||
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
|
||||
void Mutex::unlock() { xSemaphoreGive(this->handle_); }
|
||||
|
||||
// only affects the executing core
|
||||
// so should not be used as a mutex lock, only to get accurate timing
|
||||
IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace esphome {
|
||||
uint32_t random_uint32() { return os_random(); }
|
||||
bool random_bytes(uint8_t *data, size_t len) { return os_get_random(data, len) == 0; }
|
||||
|
||||
// ESP8266 Mutex is defined inline in helpers.h when ESPHOME_THREAD_SINGLE is set.
|
||||
// ESP8266 Mutex is defined inline as a no-op in helpers.h when USE_ESP8266 (or USE_RP2040) is set,
|
||||
// independent of the ESPHOME_THREAD_SINGLE thread model define.
|
||||
|
||||
IRAM_ATTR InterruptLock::InterruptLock() { state_ = xt_rsil(15); }
|
||||
IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(state_); }
|
||||
|
||||
@@ -15,12 +15,6 @@ bool random_bytes(uint8_t *data, size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Mutex::Mutex() { handle_ = xSemaphoreCreateMutex(); }
|
||||
Mutex::~Mutex() {}
|
||||
void Mutex::lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
|
||||
bool Mutex::try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
|
||||
void Mutex::unlock() { xSemaphoreGive(this->handle_); }
|
||||
|
||||
// only affects the executing core
|
||||
// so should not be used as a mutex lock, only to get accurate timing
|
||||
IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
|
||||
|
||||
@@ -35,7 +35,7 @@ bool random_bytes(uint8_t *data, size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// RP2040 Mutex is defined inline in helpers.h when ESPHOME_THREAD_SINGLE is set.
|
||||
// RP2040 Mutex is defined inline in helpers.h for RP2040/ESP8266 builds.
|
||||
|
||||
IRAM_ATTR InterruptLock::InterruptLock() { state_ = save_and_disable_interrupts(); }
|
||||
IRAM_ATTR InterruptLock::~InterruptLock() { restore_interrupts(state_); }
|
||||
|
||||
+10
-4
@@ -1883,6 +1883,16 @@ class Mutex {
|
||||
void lock() {}
|
||||
bool try_lock() { return true; }
|
||||
void unlock() {}
|
||||
#elif defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
// FreeRTOS platforms: inline to avoid out-of-line call overhead.
|
||||
Mutex() { handle_ = xSemaphoreCreateMutex(); }
|
||||
~Mutex() = default;
|
||||
void lock() { xSemaphoreTake(this->handle_, portMAX_DELAY); }
|
||||
bool try_lock() { return xSemaphoreTake(this->handle_, 0) == pdTRUE; }
|
||||
void unlock() { xSemaphoreGive(this->handle_); }
|
||||
|
||||
private:
|
||||
SemaphoreHandle_t handle_;
|
||||
#else
|
||||
Mutex();
|
||||
~Mutex();
|
||||
@@ -1891,13 +1901,9 @@ class Mutex {
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
SemaphoreHandle_t handle_;
|
||||
#else
|
||||
// d-pointer to store private data on new platforms
|
||||
void *handle_; // NOLINT(clang-diagnostic-unused-private-field)
|
||||
#endif
|
||||
#endif // single-threaded check
|
||||
};
|
||||
|
||||
/** Helper class that wraps a mutex with a RAII-style API.
|
||||
|
||||
Reference in New Issue
Block a user