ImageBuffer reader: one waiting thread at a time looks at the buffer
Every rugnux worker waiting for an image called ImageBuffer::GetImage every millisecond, and GetStatus every 100 polls. Each call takes the buffer's mutex and scans every slot, so sixteen waiting workers contended with the forward threads for the lock they put the images in under (GetImageSlot, ReadyToSend). Now one waiting thread at a time asks the buffer, at most every 2 ms, with a single GetStatus, and notes the images it holds in a per-reader bitmap; the other waiters sleep on a condition variable and are woken when it is refreshed or the collection ends. GetImage is called once, for an image known to be there (or given up on). MAX_IMAGE_LAG and Ended() mean what they did. ImageBuffer itself is unchanged. The test gains eight readers waiting at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f731db81d
commit
d356cc5da5
3 files changed
+72
-17
No files matched your search
@@ -31,7 +31,7 @@ TEST_CASE("JFJochImageBufferReader", "[JFJochReader]") {
|
||||
DiffractionExperiment experiment(DetJF(1));
|
||||
experiment.ImagesPerTrigger(200);
|
||||
|
||||
ImageBuffer buffer(4 * experiment.GetImageBufferLocationSize());
|
||||
ImageBuffer buffer(16 * experiment.GetImageBufferLocationSize());
|
||||
buffer.StartMeasurement(experiment);
|
||||
|
||||
StartMessage start{};
|
||||
@@ -73,6 +73,20 @@ TEST_CASE("JFJochImageBufferReader", "[JFJochReader]") {
|
||||
REQUIRE(pending.wait_for(std::chrono::seconds(5)) == std::future_status::ready);
|
||||
REQUIRE(pending.get());
|
||||
|
||||
// Many readers waiting at once, as rugnux's workers do: each gets its image as it comes.
|
||||
std::vector<std::future<bool>> waiting;
|
||||
for (int64_t i = 2; i < 10; i++)
|
||||
waiting.push_back(std::async(std::launch::async, [&reader, i] {
|
||||
JFJochReaderRawImage r;
|
||||
return reader.ReadRawImage(i, r) && r.image.GetWidth() > 0;
|
||||
}));
|
||||
for (int64_t i = 2; i < 10; i++)
|
||||
PutImage(buffer, experiment, i, pixels);
|
||||
for (auto &w: waiting) {
|
||||
REQUIRE(w.wait_for(std::chrono::seconds(5)) == std::future_status::ready);
|
||||
REQUIRE(w.get());
|
||||
}
|
||||
|
||||
// Images arrive in order, give or take a few: one still missing when an image MAX_IMAGE_LAG past
|
||||
// it is there is lost, while one nearer may still come.
|
||||
PutImage(buffer, experiment, 150, pixels);
|
||||
|
||||
Reference in new issue
Block a user