#include "RingBuffer.h" void rb_push(rb_t* rb, int el){ if(rb->filled) return; rb->data[rb->w_pos] = el; rb->w_pos = (rb->w_pos + 1) % rb->size; if(rb->w_pos == rb->r_pos) rb->filled = true; } int rb_pop(rb_t* rb){ if(rb->w_pos == rb->r_pos && !rb->filled){ rb->error = true; return 0; } int ret = rb->data[rb->r_pos]; rb->r_pos = (rb->r_pos + 1) % rb->size; rb->filled = false; return ret; }