{{ Ring buffer ** A more simple version of q.spin with the same API. }} CON {{ Tweakable constants }} Q_MAX = 4 Q_BITS = 7 CON {{ Non-tweakable constants }} Q_SIZE = 1<Q_MAX unlock abort ERR_OUT_OF_QUEUES q_next:=buffer_next[i]~~ writepoint[i]~ readpoint[i]~ i++ unlock PUB purge(i) | next_page,old_page i-- if i<0 OR i=>Q_MAX abort ERR_Q_INVALID readpoint[i]:=writepoint[i] PUB delete(i) | old_page purge(i) i-- lock ' Sanity check if buffer_next[i] <> 255 unlock abort ERR_Q_INVALID ' Insert Queue back into pool buffer_next[i]:=q_next q_next:=i unlock PUB bytesFree(i) i-- if i<0 OR i=>Q_MAX return 0 return buffer_mask-((writepoint[i]-readpoint[i])&buffer_mask) PUB push(i,b) | p i-- if i<0 OR i=>Q_MAX abort ERR_Q_INVALID if (readpoint[i]<> (writepoint[i] + 1) & buffer_mask) buffer[i<Q_SIZE bytemove(@buffer+i<Q_MAX abort ERR_Q_INVALID if (readpoint[i]<>writepoint[i]) val := buffer[i<Q_MAX abort ERR_Q_INVALID len:=((writepoint[i]-readpoint[i])&buffer_mask) if maxlenQ_SIZE bytemove(ptr,@buffer+i<