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

Message ID 20210130001915.489703-1-niklas.soderlund@ragnatech.se
Headers show
Series
  • cam: Fix races in event loop and long request processing times
Related show

Message

Niklas Söderlund Jan. 30, 2021, 12:19 a.m. UTC
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(-)