From patchwork Fri Dec 3 16:46:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15020 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 83B9CBF415 for ; Fri, 3 Dec 2021 16:46:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 396DB60868; Fri, 3 Dec 2021 17:46:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dKS7Ycer"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 508B760862 for ; Fri, 3 Dec 2021 17:46:38 +0100 (CET) Received: by mail-pf1-x433.google.com with SMTP id z6so3428901pfe.7 for ; Fri, 03 Dec 2021 08:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8AjrLQa6KvevGIzZ2Uw7/ytvhbTojq+0pxD3Ib25aUw=; b=dKS7Ycer1TOUHoU2S6dY1xd4I8vgUEoKYWvPq4G4bWQcgKXxIppNoFeJSW9BNrUY+I GP38FyiB04MmoifR4wrRK2oK32Qdje2/a/rRUU1iznnAJl7Dmk/V6OQWAEkL2daXIYuI G07CaSqY26CWvUU8giTGCfifXi9UdxULr6mJc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8AjrLQa6KvevGIzZ2Uw7/ytvhbTojq+0pxD3Ib25aUw=; b=hGIqN/FuPqkNH5QCcvFI2IBGysN8YYfJdr5QutT8jt7nXtfNdjztvt9eb4rkWJYahV aBci/FGs19p2lu/TzjpdA+NI8VGiMVbPlLa/rCSR86zgmKLRjnfHNyCWCuKpx3NdBJTz c4R/kVG/K12/Z+ZX3Z4St13WlTq+knQXhKy22WrF7kTS8vQuwj31FhkIzWYZNZEvkAmb lc6GSyIbrYD0Ghb11F2ceNKqPEioaGmMQKftkpb5yjvC9KOw2Q8uTez1okWDzlv67Q22 axfhARQAs680xPkbfDTwgTZyS5cVIDtr71i5zNpPsUtJmltTuAp3L02k0DBIFBrjFa/T t2zw== X-Gm-Message-State: AOAM533U9+DMzEJ1XRE+GbJcFdVAKiQoF9d5E1b8tRPhOSmIO9U77A7W oKIr+m8c28gQWTSYPHyH2QPXtr9uiVPgFQ== X-Google-Smtp-Source: ABdhPJzj9rQDLkDu1KAuWSXZeIkWcG0qw9SKxh/KUpVO3RnIvrMS3b4cRhaxaXJE1JYtzgbnXq9iCQ== X-Received: by 2002:a63:f651:: with SMTP id u17mr5212534pgj.256.1638549996666; Fri, 03 Dec 2021 08:46:36 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id h18sm4123149pfh.172.2021.12.03.08.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 08:46:36 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 01:46:19 +0900 Message-Id: <20211203164619.1541033-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203164619.1541033-1-hiroh@chromium.org> References: <20211203164619.1541033-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/7] v4l2: v4l2_camera: Apply clang thread safety annotation 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" This annotates member functions and variables of V4L2Camera by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/v4l2/v4l2_camera.cpp | 5 ++--- src/v4l2/v4l2_camera.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index 157ab94e..6d571953 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -71,11 +71,10 @@ std::vector V4L2Camera::completedBuffers() { std::vector v; - bufferLock_.lock(); + MutexLocker lock(bufferLock_); for (std::unique_ptr &metadata : completedBuffers_) v.push_back(*metadata.get()); completedBuffers_.clear(); - bufferLock_.unlock(); return v; } @@ -278,7 +277,7 @@ int V4L2Camera::qbuf(unsigned int index) void V4L2Camera::waitForBufferAvailable() { MutexLocker locker(bufferMutex_); - bufferCV_.wait(locker, [&] { + bufferCV_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(bufferMutex_) { return bufferAvailableCount_ >= 1 || !isRunning_; }); if (isRunning_) diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 9307d61d..0d5a8948 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -39,7 +39,7 @@ public: void bind(int efd); void unbind(); - std::vector completedBuffers(); + std::vector completedBuffers() LIBCAMERA_TSA_EXCLUDES(bufferLock_); int configure(libcamera::StreamConfiguration *streamConfigOut, const libcamera::Size &size, @@ -58,13 +58,14 @@ public: int qbuf(unsigned int index); - void waitForBufferAvailable(); - bool isBufferAvailable(); + void waitForBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_); + bool isBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_); bool isRunning(); private: - void requestComplete(libcamera::Request *request); + void requestComplete(libcamera::Request *request) + LIBCAMERA_TSA_EXCLUDES(bufferLock_); std::shared_ptr camera_; std::unique_ptr config_; @@ -77,11 +78,12 @@ private: std::vector> requestPool_; std::deque pendingRequests_; - std::deque> completedBuffers_; + std::deque> completedBuffers_ + LIBCAMERA_TSA_GUARDED_BY(bufferLock_); int efd_; libcamera::Mutex bufferMutex_; libcamera::ConditionVariable bufferCV_; - unsigned int bufferAvailableCount_; + unsigned int bufferAvailableCount_ LIBCAMERA_TSA_GUARDED_BY(bufferMutex_); };