And while we are at it, fix the ring buffer to be much more understandable. Things done in here:
Split the ring buffer into a separate source file and library (commit 2b65ab4).
Write tests for the ring buffer, testing out various aspects. Along the way, figured out that the previous implementation was very difficult to understand (and possibly buggy), so clean up the ring buffer to be much easier to understand, and add the tests to ensure it stays that way.
And while we are at it, fix the ring buffer to be much more understandable. Things done in here: