From af93ea4aef081fd7df2ca18c6cbbc03e22c53e04 Mon Sep 17 00:00:00 2001 From: Oleg Alexandrov Date: Mon, 20 Nov 2023 19:57:08 -0800 Subject: [PATCH] Add comments to the batch streamer --- examples/batch-streamer/batch_streamer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/batch-streamer/batch_streamer.cpp b/examples/batch-streamer/batch_streamer.cpp index 35eadb7203..65172b49e9 100644 --- a/examples/batch-streamer/batch_streamer.cpp +++ b/examples/batch-streamer/batch_streamer.cpp @@ -27,17 +27,20 @@ void makeConsumer() while (true) { { - // Make the consumer ready + // Tell the producer that the consumer is ready std::lock_guard l(mutex); ready = true; } + // Exit the lock first, so the producer can grab the lock and do work cv.notify_one(); { + // Wait for the point to be produced std::unique_lock l(mutex); cv.wait(l, []{ return produced; }); + // Consume the point std::cout << "Consumed point: " << x << ", " << y << ", " << z << " (count: " << point_count << ")\n"; produced = false; @@ -55,8 +58,8 @@ void makeConsumer() bool producePoint(pdal::PointRef& p) { { - // Waiting for the consumer to be ready and to have consumed previous - // point + // Waiting for the consumer to be ready and to have consumed the + // previous point std::unique_lock l(mutex); cv.wait(l, []{ return ready; }); cv.wait(l, []{ return !produced; });