Add should_fetch to lockless_queue so we can conditionally fetch
For logging, we want to be able to only fetch the next message if it is
time to do so. This adds a callback which is provided all the context
information at the right point to decide if we actually fetch or not.
Next step is to actually expose it through EventLoop.
Change-Id: Ic15eedc46116f8acfcb5a80ed551e89e9d6b7fa8
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/ipc_lib/queue_racer.h b/aos/ipc_lib/queue_racer.h
index 3e5ca94..87f2cce 100644
--- a/aos/ipc_lib/queue_racer.h
+++ b/aos/ipc_lib/queue_racer.h
@@ -48,7 +48,12 @@
// necesitates a loser check at the end.
//
// If both are set, run an even looser test.
- void RunIteration(bool race_reads, int write_wrap_count);
+ //
+ // set_should_read is used to determine if we should pass in a valid
+ // should_read function, and should_read_result is the return result of that
+ // function.
+ void RunIteration(bool race_reads, int write_wrap_count, bool set_should_read,
+ bool should_read_result);
size_t CurrentIndex() {
return LocklessQueueReader(queue_).LatestIndex().index();
@@ -64,7 +69,8 @@
// clean up all the threads. Otherwise we get an assert on the way out of
// RunIteration instead of getting all the way back to gtest.
void CheckReads(bool race_reads, int write_wrap_count,
- ::std::vector<ThreadState> *threads);
+ ::std::vector<ThreadState> *threads, bool set_should_read,
+ bool should_read_result);
LocklessQueue queue_;
const uint64_t num_threads_;
@@ -80,6 +86,14 @@
::std::atomic<uint64_t> started_writes_;
// Number of writes completed.
::std::atomic<uint64_t> finished_writes_;
+
+ std::function<bool(uint32_t, monotonic_clock::time_point,
+ realtime_clock::time_point, monotonic_clock::time_point,
+ realtime_clock::time_point, uint32_t, UUID, size_t)>
+ should_read_ = [](uint32_t, monotonic_clock::time_point,
+ realtime_clock::time_point, monotonic_clock::time_point,
+ realtime_clock::time_point, uint32_t, UUID,
+ size_t) { return true; };
};
} // namespace ipc_lib