Improve const-correctness in the LocklessQueue code

This will allow using a read-only mapping for reading data from queues
in ShmEventLoop. This will make it much harder for code reading from a
queue to accidentally modify it.

This involves splitting up LocklessQueue into individual components.
This makes it much more obvious what state is used where, and allows
adding some consts.

Change-Id: Ic83b0d2169e6dfae3eec656aa8e49852125698d9
diff --git a/aos/ipc_lib/queue_racer.h b/aos/ipc_lib/queue_racer.h
index eaeedd4..7e92693 100644
--- a/aos/ipc_lib/queue_racer.h
+++ b/aos/ipc_lib/queue_racer.h
@@ -14,8 +14,7 @@
 // them together to all write at once.
 class QueueRacer {
  public:
-  QueueRacer(LocklessQueueMemory *memory, int num_threads,
-             uint64_t num_messages, LocklessQueueConfiguration config);
+  QueueRacer(LocklessQueue queue, int num_threads, uint64_t num_messages);
 
   // Runs an iteration of the race.
   //
@@ -35,13 +34,14 @@
   void RunIteration(bool race_reads, int write_wrap_count);
 
   size_t CurrentIndex() {
-    LocklessQueue queue(memory_, config_);
-    return queue.LatestQueueIndex().index();
+    return LocklessQueueReader(queue_).LatestIndex().index();
   }
 
  private:
   // Wipes the queue memory out so we get a clean start.
-  void Reset() { memset(memory_, 0, LocklessQueueMemorySize(config_)); }
+  void Reset() {
+    memset(queue_.memory(), 0, LocklessQueueMemorySize(queue_.config()));
+  }
 
   // This is a separate method so that when all the ASSERT_* methods, we still
   // clean up all the threads.  Otherwise we get an assert on the way out of
@@ -49,7 +49,7 @@
   void CheckReads(bool race_reads, int write_wrap_count,
                   ::std::vector<ThreadState> *threads);
 
-  LocklessQueueMemory *memory_;
+  LocklessQueue queue_;
   const uint64_t num_threads_;
   const uint64_t num_messages_;
 
@@ -60,8 +60,6 @@
   ::std::atomic<uint64_t> started_writes_;
   // Number of writes completed.
   ::std::atomic<uint64_t> finished_writes_;
-
-  const LocklessQueueConfiguration config_;
 };
 
 }  // namespace ipc_lib