[libcamera-devel] [PATCH v3 0/2] cam: Fix races in event loop and long request processing times

Niklas Söderlund niklas.soderlund at ragnatech.se
Sat Jan 30 01:19:13 CET 2021


Hello,

Using cam to writing requests to (slow) media sometimes lock cam in an
unbreakable loop. At the heart of the problem is that when request
processing was moved from the camera to the main thread subtle races in
the cam event loop implementation where exposed.

The races are easily trigged by having callbacks injected into the even
loop that takes a long time to process. The only callbacks cam currently
injects to the event loop are processing of completed requests. So by
increasing there processing time by writing them to disk the races where
trigged.

This series fixes two different issues found when debugging this. Patch
1/2 solves a design issue in the event loop implementation where the
callback queue can be flooded which prevents termination of the loop.
While patch 2/2 solves a cam design issue where the --capture=N behavior
of only capturing N requests where broken but hidden by the problem in
patch 1/2.

Niklas Söderlund (2):
  cam: event_loop: Stop queuing calls when the event loop are exiting
  cam: Only queue the exact number of requests asked for

 src/cam/capture.cpp    | 16 +++++++++++++---
 src/cam/capture.h      |  2 ++
 src/cam/event_loop.cpp | 21 +++++++++------------
 src/cam/event_loop.h   |  2 +-
 4 files changed, 25 insertions(+), 16 deletions(-)

-- 
2.30.0



More information about the libcamera-devel mailing list