From patchwork Wed Apr 8 11:56:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26510 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8B65EC32BB for ; Wed, 8 Apr 2026 11:56:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 436D762E13; Wed, 8 Apr 2026 13:56:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="cgw+A09f"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="jg7hkND8"; dkim-atps=neutral Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 189C462E34 for ; Wed, 8 Apr 2026 13:56:38 +0200 (CEST) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 638BOaDe1619593 for ; Wed, 8 Apr 2026 11:56:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=STA4e7kdkhh OHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=cgw+A09fAuCJ9XvGS+/H90bwDAS zP6b6/WGeBKJCiVNMv+BZol/vxeG5hv6YqBTsu+Cmu/KuJS+/+xpBKBa6xPy918u mFPnKG5JDaB3EIxnT6uVKktM7wWJmot00xH75NClt0RtSRECxTB+UesXjJnrLiga Hioz2GwiLDhuTBChCVmwB26U7DTkrZW5lstAwC0sI8R2R7jHUTghm9UUhsqyXxNy KmsxUAHsQ5Fy640oG8g1zhgwfJ1Kci8GJ3ZoImmVVgIuTkCkan5JoZjbalpYMjyB 11YcyGLKxfapjZJ8SuZSJbKBFEPsPMJaidIPHiGg9FdrHo6kJ0z9xdPDAEQ== Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ddacrjnvq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 08 Apr 2026 11:56:37 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-50d831e8083so76716411cf.3 for ; Wed, 08 Apr 2026 04:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1775649397; x=1776254197; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=STA4e7kdkhhOHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=jg7hkND8182C0s7dZ/ohDdbcTeJY8s1qoL3loNzsV2DAY+gzLA35ypYtTOTKzHZdx/ C+UIdlwPr52Fxlpx2WR6nDzCBrRxaoeeSldDwBv9aFLdpB2B+5MS1pm2gSY5BaR0vX3H fK+E7RPti5JwDpBEpQIBJn9NQLdCAenIP+XW6EX/7UWBtUPPr6RZVOq3/hBdsXxbxtEJ scwyD+qksTOeHKU5jlzgopTy5SF/yOEZeeoNa2h1f3A71CkB/GFMZ9KqZ4tlyrmJuRrI 2qhRdR29uN0VXCLb1SXJhZgmjYZpkF6Di6VRFGe4Q34UGuyO79mgXt34Avlz+JwnMg6h LFAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775649397; x=1776254197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=STA4e7kdkhhOHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=pHR7+WNJnHaQryGP+5XDuxMolOwE2nnMCsbXTvSfHD2h+vmAREmsnR81w/Aok/f6mk Au4tm5VDYLadXEz11UCYnLQh7seNj07QX9Xzp1ijN9j3vngB9GBsM2VbonQIiUjmlpfi W9izkTFX1YrRtVqjJwxz3ZFUFTcU9xyckvP6d4rdhEScxHMEaLqPcz79c4zLKG0kwQD4 Ew67hHPmKhThiN2xo4xNw3XmDPtq9VLQIJDxHYqDurvGjlqZmVhmurDz+76kcRtpMY6Z bvv4o5rqhXaGjCM+N18e5CO9eK0kt1cFSeU/ZIKku7tzO1Al2BT5HQXbdj7Aiq+++qaB ALXw== X-Gm-Message-State: AOJu0YyZCCbTMBd8Y13hl6+reT+yhNAjT/Qshz8tHStDV7DOBkPBggBf Nj3w5WE3jCBBnGYnruHktaYGVECoc+V9GgxeoY43bbRMbTgDv7hDbfaU4f/d6uT39aGy23yrlx1 mZN8FkOv6jAOPAeGh8K3TJ0OEAlveIlaTcAEJfyssaoEF+OdKa0lC+nl3x13O1bQYYNPZzvrmrM qFMlJujSzF X-Gm-Gg: AeBDieux8wVbfsB2sM8ooG4iomWVG9ghLH8Eaz2n29rTzcIAIBOw5AQyeUSSctXFcRD vsSqzIrNS8hs5/YhYm2iALu/l/+J+ux8FJRlcrB3tNjG1DcxJIiY/AyO9/eqfhIM4j6m7zYHIoQ w5JppfHQ6kTzY1xhb6qOtHpXaYJ1GvVbzN15sAVB/ubvoyIOH5B7LhDEP0MWDw88g0+Rivt/TzZ qfpoXvQ4vsD+a0qMXhCk0uZnyTCU1ISwlO53CNmdY5yaALYjV6pNEOmy5DjfgDZIF/Colk9ZPrv woeNC9aTHrndWc8xHA7xf225TKkNJ9tQfiVatmijM12a87DE0FDIVbYuJgH88MHSo+gqIY17nJI CFHXDOEwy7htkUgSTENdezXsSwq308NKngFl4f43QHaxQeKUEaAdcmE2NUqjSutGOhxdT2DfFmE LsM/NAztNPezORx01ZU/gCRrFf7Qy0HExL X-Received: by 2002:a05:622a:2b03:b0:509:34b8:a373 with SMTP id d75a77b69052e-50d62cbfb5fmr310374391cf.32.1775649396856; Wed, 08 Apr 2026 04:56:36 -0700 (PDT) X-Received: by 2002:a05:622a:2b03:b0:509:34b8:a373 with SMTP id d75a77b69052e-50d62cbfb5fmr310374041cf.32.1775649396421; Wed, 08 Apr 2026 04:56:36 -0700 (PDT) Received: from t14s (2001-1c00-0c32-7800-07d4-cca3-ec08-7ac7.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:7d4:cca3:ec08:7ac7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3c97219dsm632410766b.5.2026.04.08.04.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 04:56:35 -0700 (PDT) From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Loic Poulain , Hans de Goede Subject: [PATCH 3/3] libcamera: v4l2_device: add lock() and unlock() methods Date: Wed, 8 Apr 2026 13:56:30 +0200 Message-ID: <20260408115630.12456-4-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> References: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: D6GuC2bsj-LERxRsyyq-0HjO9I5R8P-B X-Proofpoint-GUID: D6GuC2bsj-LERxRsyyq-0HjO9I5R8P-B X-Authority-Analysis: v=2.4 cv=WZs8rUhX c=1 sm=1 tr=0 ts=69d64275 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=qZCpo_c2fvnUBkGHUDcA:9 a=a_PwQJl-kcHnX1M80qC6:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA4MDExMCBTYWx0ZWRfX4sSW43JZFtP6 DWp096ktGdTC42X0Hk4AJikJQNu0A2iiJBVJtNXCaIlkT2tAEd6c7LTybRPeDcazHoTO439BWkM p31uj4MZLlLAIfp5h4YMvosAkjPLotk1EviS6+M+NBNkzreJh569PKuJLgUChtRD5EZo/ipAcOX g9sSYJ1MpeE7AnW/Xr9qC/rSWgzt923j+pBtx0lUJkDsHxBx/txgAFnUrHhCNbBIxPNENi9RncM OSkvSfE9BeU45QqmrQKwmMdaf2XjxtQufgZkcOImg1ACcgjts3HNbUOmhZyqgH2fS5cgR5u8xJU SGOxHyNZuC3Y/BI6zdwSRiEPAOpX/sb5XAqwjdMpHTTq/nMlDp9R+1gYPr6RG3G4mJ+S98waCcw DNGBL7EC1qib5F+wh+Xa7N/iOKNdPjgXD9LXvPkVkfaeug2KO7+yxai4u/0CQ8WQ3XiYGqBad2X gF5q9MYVV8rUPPr6dcw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1143, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-04-08_03,2026-04-08_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604080110 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add lock() and unlock() methods to allow pipeline-handlers to do more fine grained locking the locking at the media-device label. Signed-off-by: Hans de Goede --- include/libcamera/internal/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index dbbd118ab..f34f5f2f1 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -52,6 +52,9 @@ public: void updateControlInfo(); + bool lock(); + void unlock(); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index b49d73b1c..e8764b37e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -147,6 +147,43 @@ void V4L2Device::close() fd_.reset(); } +/** + * \brief Lock the device to prevent it from being used by other instances of + * libcamera + * + * Multiple instances of libcamera might be running on the same system, at the + * same time. To allow the different instances to coexist, system resources like + * v4l2 devices must be accessible for enumerating the cameras they provide at + * all times, while still allowing an instance to lock a resource while it + * prepares to actively use a camera from the resource. + * + * \return True if the device could be locked, false otherwise + * \sa unlock() + */ +bool V4L2Device::lock() +{ + if (!fd_.isValid()) + return false; + + if (lockf(fd_.get(), F_TLOCK, 0)) + return false; + + return true; +} + +/** + * \brief Unlock the device and free it for use for libcamera instances + * + * \sa lock() + */ +void V4L2Device::unlock() +{ + if (!fd_.isValid()) + return; + + std::ignore = lockf(fd_.get(), F_ULOCK, 0); +} + /** * \fn V4L2Device::isOpen() * \brief Check if the V4L2 device node is open