'Buffer Full strategies, RTOS, Unix
I am looking to extend the CMSIS RTOS2-compliant RTX5 kernel with some I/O primitives, in particular for reading bytes from a UART and placing them in a ringBuffer. This is on a cortex-m3. An ISR is the producer, writing into the ringbuffer. Some thread is then the consumer, reading from the ringbuffer. The thread will likely use the SVC call to 'trap' to kernel mode.
I am trying to avoid any form of locking, esp the reader locking out all interrupts while it xfers bytes from the ringbuffer to some application/userspace buffer. This is a bare-metal system.
What is the standard behavior (if one exists) on say FreeRTOS, Micrium, other RTOS, even Linux, if the writer just keeps producing data and the reader is not 'keeping up'? Some buffer must fill up somewhere, and what happens next?
WLOG, let's say my ringbuffer is 4 bytes big. Producer adds 4 bytes: A B C and D. It then goes to write E, but the reader hasn't read anything yet:
1 Should writer simply discard E, so reader will (eventually) read A B C and D, freeing up room for new bytes.
2 Should writer bump the read cursor to position B, and write E over A. Now the reader will at least read 'in-order' data B C D and E, but A is lost.
3 Should writer simply overwrite A with E but not move read cursor? Now reader will see E B C and D.
My ISR can, in theory, interrupt my reader at any time, modulo critical regions in the reader set up to lock out the ISR.
I am on a memory-constrained device, I can't just 'add more buffer space'.
Wondering what others have done here, any help appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
