Add items_waiting/is_empty introspection to ring buffers#68
Merged
Conversation
Expose committed-item counts and emptiness checks on the SPSC ring buffer (ESP and host) and the audio ring buffer wrapper.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds lightweight introspection APIs to the ring buffer abstractions so consumers can query whether buffered audio (or other items) are pending and how many are queued, enabling underflow-avoidance logic.
Changes:
- Add
SpscRingBuffer::items_waiting()andSpscRingBuffer::is_empty()for both ESP (viavRingbufferGetInfo) and host (via a newitems_waiting_counter). - Track
items_waiting_in the host implementation (increment on commit, decrement on receive) and makemtx_mutableto allow locking inconstaccessors. - Add
SendspinAudioRingBuffer::chunks_waiting()andSendspinAudioRingBuffer::is_empty()as thin wrappers over the underlying SPSC ring buffer.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/platform/spsc_ring_buffer.h |
Adds new introspection methods; host implementation adds items_waiting_ counter and updates synchronization to support const accessors. |
src/audio_ring_buffer.h |
Exposes audio-specific wrappers for the underlying ring buffer introspection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Return 0 when the ring buffer has not been created, matching the host implementation's safe default and avoiding a null-handle dereference in vRingbufferGetInfo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Exposes two introspection methods on the ring buffer types:
SpscRingBuffer::items_waiting()/is_empty(): count of committed items written but not yet received by the consumer, on both the ESP (FreeRTOSvRingbufferGetInfo) and host implementations. The host implementation gains anitems_waiting_counter (incremented on commit, decremented on receive) andmtx_is mademutableso the const accessors can lock.AudioRingBuffer::chunks_waiting()/is_empty(): thin wrappers delegating to the underlying SPSC ring buffer.Why
These accessors let the consumer query how much audio is queued so it can detect an empty/near-empty buffer and stuff zeros to prevent underflow to prevent audible glitches at the start of playback.
Notes for reviewers