Interrupt-Safe Ring Buffer

Hard C Concurrency
Solve this problem

Implement a ring buffer in C for use in interrupt contexts. Must be lock-free and interrupt-safe using volatile indices. Designed for UART RX ISR.

Constraints

  • Size=64 bytes.
  • volatile head/tail.
  • push usable from ISR.
  • pop from main.
  • Return -1 on full/empty.
  • No dynamic memory.
Starter codeC
1#include <stdint.h>2int rb_push(uint8_t d);3int rb_pop(uint8_t* d);