Blinkinlabs / ch554_sdcc

CH554 software development kit for SDCC
297 stars 70 forks source link

race condition in ring buffer #24

Open nerdralph opened 4 years ago

nerdralph commented 4 years ago

UartByteCount is modified in the UART1 ISR and in main. If the UART1 interrupt occurs between lines 590 and 598, the received byte will be dropped. https://github.com/Blinkinlabs/ch554_sdcc/blob/master/examples/usb_device_cdc/main.c#L598

I don't see a simple fix. I think it would be best to replace the ring buffer code with a thread-safe version. I recently published a tiny ring buffer that would be a good fit. https://github.com/nerdralph/RingBuffer