mirror of
https://github.com/esphome/esphome.git
synced 2025-08-07 02:47:47 +00:00
tidy
This commit is contained in:
parent
8e8ef83780
commit
10a03ad538
@ -29,7 +29,7 @@ void SchedulerRapidCancellationComponent::run_rapid_cancellation_test() {
|
|||||||
threads.reserve(NUM_THREADS);
|
threads.reserve(NUM_THREADS);
|
||||||
|
|
||||||
for (int thread_id = 0; thread_id < NUM_THREADS; thread_id++) {
|
for (int thread_id = 0; thread_id < NUM_THREADS; thread_id++) {
|
||||||
threads.emplace_back([this, thread_id]() {
|
threads.emplace_back([this]() {
|
||||||
for (int i = 0; i < OPERATIONS_PER_THREAD; i++) {
|
for (int i = 0; i < OPERATIONS_PER_THREAD; i++) {
|
||||||
// Use modulo to ensure multiple threads use the same names
|
// Use modulo to ensure multiple threads use the same names
|
||||||
int name_index = i % NUM_NAMES;
|
int name_index = i % NUM_NAMES;
|
||||||
|
@ -48,7 +48,7 @@ void SchedulerSimultaneousCallbacksComponent::run_simultaneous_callbacks_test()
|
|||||||
std::string name = ss.str();
|
std::string name = ss.str();
|
||||||
|
|
||||||
// Schedule callback for exactly DELAY_MS from now
|
// Schedule callback for exactly DELAY_MS from now
|
||||||
this->set_timeout(name, DELAY_MS, [this, thread_id, i, name]() {
|
this->set_timeout(name, DELAY_MS, [this, name]() {
|
||||||
// Increment concurrent counter atomically
|
// Increment concurrent counter atomically
|
||||||
int current = this->callbacks_at_once_.fetch_add(1) + 1;
|
int current = this->callbacks_at_once_.fetch_add(1) + 1;
|
||||||
|
|
||||||
|
@ -59,19 +59,19 @@ void SchedulerStringNameStressComponent::run_string_name_stress_test() {
|
|||||||
// Also test nested scheduling from callbacks
|
// Also test nested scheduling from callbacks
|
||||||
if (j % 10 == 0) {
|
if (j % 10 == 0) {
|
||||||
// Every 10th callback schedules another callback
|
// Every 10th callback schedules another callback
|
||||||
this->set_timeout(dynamic_name, delay, [component, i, j, callback_id]() {
|
this->set_timeout(dynamic_name, delay, [component, callback_id]() {
|
||||||
component->executed_callbacks_.fetch_add(1);
|
component->executed_callbacks_.fetch_add(1);
|
||||||
ESP_LOGV(TAG, "Executed string-named callback %d (nested scheduler)", callback_id);
|
ESP_LOGV(TAG, "Executed string-named callback %d (nested scheduler)", callback_id);
|
||||||
|
|
||||||
// Schedule another timeout from within this callback with a new dynamic name
|
// Schedule another timeout from within this callback with a new dynamic name
|
||||||
std::string nested_name = "nested_from_" + std::to_string(callback_id);
|
std::string nested_name = "nested_from_" + std::to_string(callback_id);
|
||||||
component->set_timeout(nested_name, 1, [component, callback_id]() {
|
component->set_timeout(nested_name, 1, [callback_id]() {
|
||||||
ESP_LOGV(TAG, "Executed nested string-named callback from %d", callback_id);
|
ESP_LOGV(TAG, "Executed nested string-named callback from %d", callback_id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Regular callback
|
// Regular callback
|
||||||
this->set_timeout(dynamic_name, delay, [component, i, j, callback_id]() {
|
this->set_timeout(dynamic_name, delay, [component, callback_id]() {
|
||||||
component->executed_callbacks_.fetch_add(1);
|
component->executed_callbacks_.fetch_add(1);
|
||||||
ESP_LOGV(TAG, "Executed string-named callback %d", callback_id);
|
ESP_LOGV(TAG, "Executed string-named callback %d", callback_id);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user