mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
Split LockFreeQueue into base and notifying variants to reduce memory usage
This commit is contained in:
parent
dfcc3206f7
commit
62088dfaed
@ -126,18 +126,14 @@ template<class T, uint8_t SIZE> class NotifyingLockFreeQueue : public LockFreeQu
|
|||||||
if (was_empty) {
|
if (was_empty) {
|
||||||
// Queue was empty - consumer might be going to sleep, must notify
|
// Queue was empty - consumer might be going to sleep, must notify
|
||||||
xTaskNotifyGive(task_to_notify_);
|
xTaskNotifyGive(task_to_notify_);
|
||||||
} else {
|
} else if (this->head_.load(std::memory_order_acquire) == old_tail) {
|
||||||
// Queue wasn't empty - check if consumer has caught up to previous tail
|
// Consumer just caught up to where tail was - might go to sleep, must notify
|
||||||
uint8_t head_after = this->head_.load(std::memory_order_acquire);
|
// Note: There's a benign race here - between reading head and calling
|
||||||
if (head_after == old_tail) {
|
// xTaskNotifyGive(), the consumer could advance further. This would result
|
||||||
// Consumer just caught up to where tail was - might go to sleep, must notify
|
// in an unnecessary wake-up, but is harmless and extremely rare in practice.
|
||||||
// Note: There's a benign race here - between reading head_after and calling
|
xTaskNotifyGive(task_to_notify_);
|
||||||
// xTaskNotifyGive(), the consumer could advance further. This would result
|
|
||||||
// in an unnecessary wake-up, but is harmless and extremely rare in practice.
|
|
||||||
xTaskNotifyGive(task_to_notify_);
|
|
||||||
}
|
|
||||||
// Otherwise: consumer is still behind, no need to notify
|
|
||||||
}
|
}
|
||||||
|
// Otherwise: consumer is still behind, no need to notify
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user