Add proper locking to ring buffer.