I've been writing ring buffers wrong all these years (www.snellman.net)