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/events/shm_event_loop.cc b/aos/events/shm_event_loop.cc
index 314e366..8ed6e0e 100644
--- a/aos/events/shm_event_loop.cc
+++ b/aos/events/shm_event_loop.cc
@@ -226,7 +226,8 @@
queue_index.index(), &context_.monotonic_event_time,
&context_.realtime_event_time, &context_.monotonic_remote_time,
&context_.realtime_remote_time, &context_.remote_queue_index,
- &context_.source_boot_uuid, &context_.size, copy_buffer);
+ &context_.source_boot_uuid, &context_.size, copy_buffer,
+ std::ref(should_fetch_));
if (read_result == ipc_lib::LocklessQueueReader::Result::GOOD) {
if (pin_data()) {
@@ -320,6 +321,11 @@
std::optional<ipc_lib::LocklessQueuePinner> pinner_;
Context context_;
+
+ // Pre-allocated should_fetch function so we don't allocate.
+ std::function<bool(const Context &)> should_fetch_ = [](const Context &) {
+ return true;
+ };
};
class ShmFetcher : public RawFetcher {