From patchwork Mon Nov 29 11:44:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14837 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 6CA8BBF415 for ; Mon, 29 Nov 2021 11:45:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A159605B4; Mon, 29 Nov 2021 12:45:06 +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="KBc0wTXE"; dkim-atps=neutral Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C7FD660597 for ; Mon, 29 Nov 2021 12:45:03 +0100 (CET) Received: by mail-pl1-x62f.google.com with SMTP id q17so11924120plr.11 for ; Mon, 29 Nov 2021 03:45:03 -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=fTPId8aJWvtcDKFDNSLx1VnBGzL59PNNmLExIJt0hrk=; b=KBc0wTXE+eDafmJJvHF0d8BdK8RuHBvP7y0XH/QGR82xG02CgSDpSzvXAg0nN9nBGK T6WVXetG729ZTkKb7rKytEToxIsMI71NHXOgGch6vjJS0u5OkJSn75jEGb8nL0nMAu4p 9X20swRUkoeMALqlfBStZZHYLEx4k9DMwFDHY= 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=fTPId8aJWvtcDKFDNSLx1VnBGzL59PNNmLExIJt0hrk=; b=cixNoVAoUHqlH+5Gu+RtNSFdlT0jQx2JhMol2rHrHiJsQZTkYe9yprj6c+ZRKQ1whv SmevNx8n7J524vrILfUiW/fFWYOPPx9dCC0v9xMC3b68MhrZOeONJwrTybYw+7bdJbnA iqUK2ltX1HdXCkgTGTNBGJyHlZtD9g4ZMWnGixJU4H0wKEWAlqfSRunvlmYfs4a7OlUS BE9m12sh2tNvgMxEg56klQhZvbeFMv730ToacZw3IKpiNEu/FAY3Hvvh4zAxSvhQFWMH OttfpFnxeG6maKLZl1ZEAyQZtyyzVDYiTkg4vApcT3aV2gYpOvlbU1fdVsbbsQGRE5CL iq9Q== X-Gm-Message-State: AOAM530pQ9MBRY6T7m96sdyYd3SXjSak7XHGMwODM8e2LO0xpNgr9+Be 7XEjinny6R4fbYLtu9VNVrPsv2W4dws3JQ== X-Google-Smtp-Source: ABdhPJws6EAbDLiF5qjKSHgbkBSbSvRcMh0n4Lzx4UQlnjIFQWoxaSPXR2FYqwcaFHVeMgwu9M+6Xg== X-Received: by 2002:a17:90b:3b83:: with SMTP id pc3mr37671622pjb.106.1638186301843; Mon, 29 Nov 2021 03:45:01 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:01 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:43 +0900 Message-Id: <20211129114453.3186042-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/11] libcamera: base: Introduce ConditionVariable 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" ConditionVariable is alias to std::condition_variable. This replaces std::condition_variable with the ConditionVariable. It enables replacing ConditionVariable implementation easily in the following patches. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/semaphore.h | 4 +--- include/libcamera/base/thread.h | 2 ++ src/android/camera_stream.h | 3 +-- src/libcamera/base/thread.cpp | 3 +-- src/libcamera/camera_manager.cpp | 3 +-- src/v4l2/v4l2_camera.h | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/libcamera/base/semaphore.h b/include/libcamera/base/semaphore.h index ae87d319..ec05fad3 100644 --- a/include/libcamera/base/semaphore.h +++ b/include/libcamera/base/semaphore.h @@ -7,8 +7,6 @@ #pragma once -#include - #include #include @@ -26,7 +24,7 @@ public: private: Mutex mutex_; - std::condition_variable cv_; + ConditionVariable cv_; unsigned int available_; }; diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 32ebc80a..1ebf8363 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -26,6 +27,7 @@ class Object; class ThreadData; class ThreadMain; +using ConditionVariable = std::condition_variable; using Mutex = std::mutex; using MutexLocker = std::unique_lock; diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e9da75f0..e4808369 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include @@ -154,7 +153,7 @@ private: PostProcessor *postProcessor_; libcamera::Mutex mutex_; - std::condition_variable cv_; + libcamera::ConditionVariable cv_; std::queue requests_; State state_ = State::Stopped; diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index d0ca30e3..58e1265f 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -158,7 +157,7 @@ private: std::atomic dispatcher_; - std::condition_variable cv_; + ConditionVariable cv_; std::atomic exit_; int exitCode_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index e78bb1d7..77ff3bd1 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -7,7 +7,6 @@ #include -#include #include #include @@ -63,7 +62,7 @@ private: void createPipelineHandlers(); void cleanup(); - std::condition_variable cv_; + ConditionVariable cv_; bool initialized_; int status_; diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 94263b2f..4afbb331 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -82,6 +82,6 @@ private: int efd_; libcamera::Mutex bufferMutex_; - std::condition_variable bufferCV_; + libcamera::ConditionVariable bufferCV_; unsigned int bufferAvailableCount_; }; From patchwork Mon Nov 29 11:44:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14838 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 905BEC324F for ; Mon, 29 Nov 2021 11:45:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B8D46605B8; Mon, 29 Nov 2021 12:45:06 +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="HjGrtOh3"; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1351360597 for ; Mon, 29 Nov 2021 12:45:05 +0100 (CET) Received: by mail-pj1-x1030.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so15346210pjb.5 for ; Mon, 29 Nov 2021 03:45:05 -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=CKY6AICRbf9hUVggpufuKtI4U9/jhpBFKpn2XVd4mAc=; b=HjGrtOh36vVlQ4LMb3lKh74pVRgQbi806JXorILKQauTBnHGgmgADdZrmNLlHFPeHw IZX9g/nakzyl4RLzSDNLv31O5oJDcq47ebtgyX+Vo9VbAG/4cOEJMse8w7+Ju0S6Mtrl gUvbc1DYkDGkDR4IkdMrAxRbo2K//iA384ErA= 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=CKY6AICRbf9hUVggpufuKtI4U9/jhpBFKpn2XVd4mAc=; b=jK/dxzAGUPmFKF/jVG37aFjjCFuueQ+5URxEO3WmjMfHctiAwQGFCS95N4Ma4BnCwA 79ntXpFc3yDVxBw/en/CSnfy0oJu3B5oD6uTeZ2eR6cNrBHk89IOqj+jsJjZBkDnXogK Zfk31Y3MwuBScTaGkAOkUDC9M5mb+D8mvwNTJZDUilYI0MSN2cecc4KNSpt5jpNr7kFK Iff2PtW1ggf77KxHQ4LrD+NReproD5xF+zVwzIoG5neq5DVzVTI+QstDoWa+TYBmrH0/ 1qmlbFmeoHSxLHu+B7S4U4rDOH1cISsompX3wUOU6bXUT1+QK7tkDKphXeQwQGTd0Qes ERHQ== X-Gm-Message-State: AOAM533FXmBs6Oyjf8xTlj52kRx11L22oYm9uZZ0ngklxdkdtstrJjom s1n8LLPOr/TDyxFPllIB29RNKCneyBmePQ== X-Google-Smtp-Source: ABdhPJyVyegGiFa5X1YbEe36XdUDCXXzaRnLhUNEGUn4czcXHThekskdpL/DQi4nGfv8yOuAl6SDkw== X-Received: by 2002:a17:90b:4c0d:: with SMTP id na13mr36578937pjb.206.1638186303377; Mon, 29 Nov 2021 03:45:03 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:03 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:44 +0900 Message-Id: <20211129114453.3186042-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/11] android: Consolidate mutex classes to Mutex and MutexLocker 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" std::mutex and std::unique_lcok are used in android directories, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_hal_manager.h | 6 ++---- src/android/camera_request.h | 4 ++-- src/android/camera_stream.cpp | 12 ++++++------ src/android/camera_stream.h | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 192f2fc5..c07684a1 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -18,6 +18,7 @@ #include #include +#include #include @@ -44,9 +45,6 @@ public: private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager) - using Mutex = std::mutex; - using MutexLocker = std::unique_lock; - static constexpr unsigned int firstExternalCameraId_ = 1000; CameraHalManager(); @@ -64,7 +62,7 @@ private: const camera_module_callbacks_t *callbacks_; std::vector> cameras_; std::map cameraIdsMap_; - Mutex mutex_; + libcamera::Mutex mutex_; unsigned int numInternalCameras_; unsigned int nextExternalCameraId_; diff --git a/src/android/camera_request.h b/src/android/camera_request.h index f3cb6d64..88d501a8 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -9,10 +9,10 @@ #include #include -#include #include #include +#include #include #include @@ -58,7 +58,7 @@ public: /* Keeps track of streams requiring post-processing. */ std::map pendingStreamsToProcess_; - std::mutex streamsProcessMutex_; + libcamera::Mutex streamsProcessMutex_; Camera3RequestDescriptor(libcamera::Camera *camera, const camera3_capture_request_t *camera3Request); diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 9023c13c..5a62b7cd 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -119,7 +119,7 @@ int CameraStream::configure() if (type_ == Type::Internal) { allocator_ = std::make_unique(cameraDevice_->camera()); - mutex_ = std::make_unique(); + mutex_ = std::make_unique(); int ret = allocator_->allocate(stream()); if (ret < 0) @@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer() if (!allocator_) return nullptr; - std::lock_guard locker(*mutex_); + MutexLocker locker(*mutex_); if (buffers_.empty()) { LOG(HAL, Error) << "Buffer underrun"; @@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer) if (!allocator_) return; - std::lock_guard locker(*mutex_); + MutexLocker locker(*mutex_); buffers_.push_back(buffer); } @@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces CameraStream::PostProcessorWorker::~PostProcessorWorker() { { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); state_ = State::Stopped; } @@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker() void CameraStream::PostProcessorWorker::start() { { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); ASSERT(state_ != State::Running); state_ = State::Running; } @@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run() void CameraStream::PostProcessorWorker::flush() { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); state_ = State::Flushing; lock.unlock(); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e4808369..c127a0e4 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -173,7 +173,7 @@ private: * The class has to be MoveConstructible as instances are stored in * an std::vector in CameraDevice. */ - std::unique_ptr mutex_; + std::unique_ptr mutex_; std::unique_ptr postProcessor_; std::unique_ptr worker_; From patchwork Mon Nov 29 11:44:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14839 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 8BA48BF415 for ; Mon, 29 Nov 2021 11:45:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 423C2605B4; Mon, 29 Nov 2021 12:45:10 +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="Nojlp41L"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A35A2605A6 for ; Mon, 29 Nov 2021 12:45:06 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so11621069pjj.0 for ; Mon, 29 Nov 2021 03:45:06 -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=ZOAZZb3YEiRY/bi7D7SmcCZ54QwiXVWiBu6nuv2zOfg=; b=Nojlp41LO/UwoDV0m0INyo9FzDa8ZUrYGF8/RBX6Pku7dftWW7nY7rjeCBWL+ftfyY ZQJQ1BYX4bxK5wRvdSJoKzwj51cgweSu7+y2rATUr7p8a6JgjKBi8vJZSIH58mVqJ8bI yRGyea0GfVdZ6aITs9e5NakLMeBP7WWOrP2Uc= 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=ZOAZZb3YEiRY/bi7D7SmcCZ54QwiXVWiBu6nuv2zOfg=; b=ZvrvlSxx2FEvckiLmX4PEjeo/CyXtPgj944r1cHqmF7ch13apfVoAb6ENL4rprrS/Q MAv42+8SGlNqlDquDW9hGoY8ZqekhJpWMKD6UGsDshf/5gqImHN0vM6EB6NXK2lmPdM8 uy4qTfQ2ljCK8b/BCp4RFy1jQDExvwLnRQBMgBGHfqY2v7O0L488XaxLoV9ZrLvM4Miy OQehIz0ZsJB5MhJCSi4C3hta075n5xo/qxEZZvpoCb2iuQg5xS2OPj1BQhEeflphygHk KraCsfZOscUNAdMU5xGApeyrNlhQSuil+9/OaXMOENEtj/yem77nzpCdc/+LzfJ2e2Fz cgmQ== X-Gm-Message-State: AOAM530uZBika6Aaso1JOax40/h4r2OUPbE3mg5jIhdLmzSvhQ6yYXeg Ug5lxxYii51bSLD5FnXoRTlfn/9EdWKiQg== X-Google-Smtp-Source: ABdhPJwWuf7K2R2hv6ebF74r+AjOno81sAEV5VbaGuvyKOZwlVCvL5VE2ssgK5LFe0t6Psj2WyW3tQ== X-Received: by 2002:a17:902:d2cd:b0:141:fbe2:b658 with SMTP id n13-20020a170902d2cd00b00141fbe2b658mr59418906plc.49.1638186305025; Mon, 29 Nov 2021 03:45:05 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:04 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:45 +0900 Message-Id: <20211129114453.3186042-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/11] v4l2: Consolidate mutex classes to Mutex and MutexLocker 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" std::mutex and std::unique_lcok are used in v4l2 directory, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. This also fixes vidoc_dqbuf argument to take Mutex instead of MutexLocker. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/v4l2/v4l2_camera.h | 2 +- src/v4l2/v4l2_camera_proxy.cpp | 8 ++++---- src/v4l2/v4l2_camera_proxy.h | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 4afbb331..2f6fcb3c 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -71,7 +71,7 @@ private: bool isRunning_; - std::mutex bufferLock_; + libcamera::Mutex bufferLock_; libcamera::FrameBufferAllocator *bufferAllocator_; std::vector> requestPool_; diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 3610e63c..79bc880d 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -575,7 +575,7 @@ int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) } int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - MutexLocker *locker) + Mutex *lock) { LOG(V4L2Compat, Debug) << "Servicing vidioc_dqbuf fd = " << file->efd(); @@ -593,9 +593,9 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, return -EINVAL; if (!file->nonBlocking()) { - locker->unlock(); + lock->unlock(); vcam_->waitForBufferAvailable(); - locker->lock(); + lock->lock(); } else if (!vcam_->isBufferAvailable()) return -EAGAIN; @@ -753,7 +753,7 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar ret = vidioc_qbuf(file, static_cast(arg)); break; case VIDIOC_DQBUF: - ret = vidioc_dqbuf(file, static_cast(arg), &locker); + ret = vidioc_dqbuf(file, static_cast(arg), &proxyMutex_); break; case VIDIOC_STREAMON: ret = vidioc_streamon(file, static_cast(arg)); diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index fccec241..040954dd 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -14,6 +14,8 @@ #include #include +#include + #include #include "v4l2_camera.h" @@ -57,7 +59,7 @@ private: int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - libcamera::MutexLocker *locker); + libcamera::Mutex *lock); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg); From patchwork Mon Nov 29 11:44:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14840 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 98A3DC324F for ; Mon, 29 Nov 2021 11:45:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3CDDB605B6; Mon, 29 Nov 2021 12:45:11 +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="DHRVfr0c"; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 51BE660597 for ; Mon, 29 Nov 2021 12:45:08 +0100 (CET) Received: by mail-pl1-x635.google.com with SMTP id v19so11928121plo.7 for ; Mon, 29 Nov 2021 03:45:08 -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=d5yT8zNAlqQjYlwlQgZSp7pbadJUD9JTM9ocP49aJHc=; b=DHRVfr0cdtBoR37g1NrN3hVgThd8Q0aYe6+1RrrDOk4wFzMFQRi08iZxL5rb6mJcx5 ttVrX8WOgtXp53DcNFFdxWwX46HQ6eANviQ7GY2f0K60VipWrOFUuwLfP2l6ux5KAZD0 bXp0HldFTWtNIRDiKgSOGTYotvswX6u9o1ohE= 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=d5yT8zNAlqQjYlwlQgZSp7pbadJUD9JTM9ocP49aJHc=; b=QGzcYh1Hv0zSfiBdEd0mt6gjNAV0bSVVlgI4umEbk3ccdLqGROSuW0OlHv2czLtMKJ 9whMHWXOOTd0RZNxHwu1IE1s2LRwZlHYK/iUfGuFy9yTotONvIk/LJXwnPgq3FGFGWzH 2NJrRXWYvP01/ZGAOVHlAtBfr7hT34xsoZ/l1UYEM/PUc76AONyLe12bMupDEDSV64Eu wguSLM6EYmQWlhm1M3D/MyMhtENBUEwd+DSExBrQQI99tqF7e2F43LSRG60lXuz+uYGP kYijcVbu7XetDzBDLiTi3ZD+UcnsVDrP+LIsyGXxlLCEBehlGpG0wv6jDbu2U/3g3Udu lAHQ== X-Gm-Message-State: AOAM531DK5G5AgE8X7zCE42uoTjqgiz3pokiQfn7pgVt52QzbGaJMIK8 fjbwf2vxjjqTnHY2wylREWGG9RSk2Pu9SA== X-Google-Smtp-Source: ABdhPJxsCTk2N0uzctIEPF1v66/Kk/v1Ba+A6o2GvW00lFRKTiUjDNczwe1AAeoqnpYHpBmkPJDizw== X-Received: by 2002:a17:90a:46c9:: with SMTP id x9mr38261632pjg.183.1638186306617; Mon, 29 Nov 2021 03:45:06 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:06 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:46 +0900 Message-Id: <20211129114453.3186042-5-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/11] libcamera: base: Add thread safety annotation macros 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" Clang complier is able to do a thread safety analysis with annotations [1]. This introduces the thread safety annotation macros and also enable the analysis by adding -Wthread-safety if a clang compiler is used. [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/meson.build | 1 + include/libcamera/base/thread_annotations.h | 80 +++++++++++++++++++++ meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100644 include/libcamera/base/thread_annotations.h diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index 525aba9d..1a71ce5a 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -19,6 +19,7 @@ libcamera_base_headers = files([ 'signal.h', 'span.h', 'thread.h', + 'thread_annotations.h', 'timer.h', 'utils.h', ]) diff --git a/include/libcamera/base/thread_annotations.h b/include/libcamera/base/thread_annotations.h new file mode 100644 index 00000000..e81929f6 --- /dev/null +++ b/include/libcamera/base/thread_annotations.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * thread_annotation.h - Macro of Clang thread safety analysis + */ + +#pragma once + +/* + * Enable thread safety attributes only with clang. + * The attributes can be safely erased when compiling with other compilers. + */ +#if defined(__clang__) && !defined(SWIG) +#define LIBCAMERA_TSA_ATTRIBUTE__(x) __attribute__((x)) +#else +#define LIBCAMERA_TSA_ATTRIBUTE__(x) /* no-op */ +#endif + +/* See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for these usages. */ + +#define LIBCAMERA_TSA_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(capability(x)) + +#define LIBCAMERA_TSA_SCOPED_CAPABILITY \ + LIBCAMERA_TSA_ATTRIBUTE__(scoped_lockable) + +#define LIBCAMERA_TSA_GUARDED_BY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(guarded_by(x)) + +#define LIBCAMERA_TSA_PT_GUARDED_BY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(pt_guarded_by(x)) + +#define LIBCAMERA_TSA_ACQUIRED_BEFORE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquired_before(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRED_AFTER(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquired_after(__VA_ARGS__)) + +#define LIBCAMERA_TSA_REQUIRES(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(requires_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_REQUIRES_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE_GENERIC(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_generic_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_TRY_ACQUIRE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_TRY_ACQUIRE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_EXCLUDES(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ASSERT_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(assert_capability(x)) + +#define LIBCAMERA_TSA_ASSERT_SHARED_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(assert_shared_capability(x)) + +#define LIBCAMERA_TSA_RETURN_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(lock_returned(x)) + +#define LIBCAMERA_TSA_NO_THREAD_SAFETY_ANALYSIS \ + LIBCAMERA_TSA_ATTRIBUTE__(no_thread_safety_analysis) diff --git a/meson.build b/meson.build index 7892a9e3..7147a108 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,7 @@ if cc.get_id() == 'clang' cpp_arguments += [ '-Wextra-semi', + '-Wthread-safety', ] endif From patchwork Mon Nov 29 11:44:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14841 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 28F9FBF415 for ; Mon, 29 Nov 2021 11:45:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D912D605B9; Mon, 29 Nov 2021 12:45:14 +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="EEsjJWLh"; dkim-atps=neutral Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E5BB605B7 for ; Mon, 29 Nov 2021 12:45:10 +0100 (CET) Received: by mail-pf1-x42a.google.com with SMTP id g18so16575233pfk.5 for ; Mon, 29 Nov 2021 03:45:10 -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=yMK8xuOKXl6FNLXZT5HALq7jJoQBO1uNuMrQ9ZfsbSQ=; b=EEsjJWLhNP4snEAM/q4j5YHpeo36W2zOFhBvnjzY4OjHy6/M1v04LlLahKTTsKiSo8 L7iFNn7CwZZ2/FIYmQ7S2mf2SZUfm+WnJiXIYNM8vWIcZUgKkf8xh93nqaD8ptfHSet9 4iLamDBe050ez+eOBm9yj/eesYcGZLI8Y7d0A= 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=yMK8xuOKXl6FNLXZT5HALq7jJoQBO1uNuMrQ9ZfsbSQ=; b=OutM8FC1q1OIx8t29twuH/DXaOfT7TTPc81SjMiNf1IlNOGLjdfnGLStzESUPNUG9S R6Ek5uVA4nxjXMNvVrSZdHKeJlE/svUoil42P/uITkQi7eiHeeK4A6eIrFkK6TbYnb7S XgyRXtmiPnIYovfD9W/QEem+dvdA7+37fY3tdhLE6M9pfGf5u9vsWB1PxYxvp+tI0Xnk OzrexlziWoH8QB9wyvZRSiHlizEyuU8ORtW60rSbOnwVj2AziHD2t7pvoKMFZuPMGT4m WHFLPPUsHiNQVqhira6dgg49PMMM+EuF6oV3Hlr+gxZXeXl6yWnceiR21IkGKkEzuP8F vmJg== X-Gm-Message-State: AOAM532EFTSE5S1nLvC6119KoiZpua6rIyTzwFZQy5UMVSn9JCRGG00Y oRV4jpzqr4Geul9KmA6XGvIkgFwY9Ejt4A== X-Google-Smtp-Source: ABdhPJz5xsHrF7mK0qfQvEgD/lsXX/ne7Z8Gptgru8+satJ2OtF6yRUfEgoP+6CUEiWqODcI0v9vjA== X-Received: by 2002:aa7:88d3:0:b0:49f:baac:9b51 with SMTP id k19-20020aa788d3000000b0049fbaac9b51mr38946911pff.44.1638186308275; Mon, 29 Nov 2021 03:45:08 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:07 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:47 +0900 Message-Id: <20211129114453.3186042-6-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/11] libcamera: base: Add mutex classes with thread safety annotations 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 replaces Mutex and MutexLocker with our own defined classes. The classes are annotated by clang thread safety annotations. So we can add annotation to code where the classes are used. v4l2 code needs to be annotated, which violates Mutex capability. Signed-off-by: Hirokazu Honda --- include/libcamera/base/meson.build | 1 + include/libcamera/base/mutex.h | 127 +++++++++++++++++++++++++++++ include/libcamera/base/thread.h | 7 +- src/v4l2/v4l2_camera_proxy.h | 5 +- 4 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 include/libcamera/base/mutex.h diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index 1a71ce5a..37c4435a 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -13,6 +13,7 @@ libcamera_base_headers = files([ 'flags.h', 'log.h', 'message.h', + 'mutex.h', 'object.h', 'private.h', 'semaphore.h', diff --git a/include/libcamera/base/mutex.h b/include/libcamera/base/mutex.h new file mode 100644 index 00000000..55091eb4 --- /dev/null +++ b/include/libcamera/base/mutex.h @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * thread.h - Thread support + */ + +#pragma once + +#include +#include + +#include + +namespace libcamera { + +class ConditionVariable; +class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker; + +/* \todo using Mutex = std::mutex if lib++ is used. */ +class LIBCAMERA_TSA_CAPABILITY("mutex") Mutex final +{ +public: + constexpr Mutex() + { + } + + void lock() LIBCAMERA_TSA_ACQUIRE() + { + mutex_.lock(); + } + + void unlock() LIBCAMERA_TSA_RELEASE() + { + mutex_.unlock(); + } + +private: + friend MutexLocker; + + std::mutex mutex_; +}; + +class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker final +{ +public: + explicit MutexLocker(Mutex &mutex) LIBCAMERA_TSA_ACQUIRE(mutex) + : lock_(mutex.mutex_) + { + } + + MutexLocker(Mutex &mutex, std::defer_lock_t t) noexcept LIBCAMERA_TSA_ACQUIRE(mutex) + : lock_(mutex.mutex_, t) + { + } + + MutexLocker(Mutex &mutex, std::try_to_lock_t t) noexcept LIBCAMERA_TSA_ACQUIRE(mutex) + : lock_(mutex.mutex_, t) + { + } + + MutexLocker(Mutex &mutex, std::adopt_lock_t t) noexcept LIBCAMERA_TSA_ACQUIRE(mutex) + : lock_(mutex.mutex_, t) + { + } + + ~MutexLocker() LIBCAMERA_TSA_RELEASE() + { + } + + void lock() LIBCAMERA_TSA_ACQUIRE() + { + lock_.lock(); + } + + void unlock() LIBCAMERA_TSA_RELEASE() + { + lock_.unlock(); + } + + bool try_lock() LIBCAMERA_TSA_TRY_ACQUIRE(true) + { + return lock_.try_lock(); + } + +private: + friend ConditionVariable; + + std::unique_lock lock_; +}; + +class ConditionVariable final +{ +public: + ConditionVariable() + { + } + + void notify_one() noexcept + { + cv_.notify_one(); + } + + void notify_all() noexcept + { + cv_.notify_all(); + } + + template + void wait(MutexLocker &locker, Predicate stopWaiting) + { + cv_.wait(locker.lock_, stopWaiting); + } + + template + bool wait_for(MutexLocker &locker, + const std::chrono::duration &relTime, + Predicate stopWaiting) + { + return cv_.wait_for(locker.lock_, relTime, stopWaiting); + } + +private: + std::condition_variable cv_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 1ebf8363..44678c34 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -7,15 +7,14 @@ #pragma once -#include #include -#include #include #include #include #include +#include #include #include @@ -27,10 +26,6 @@ class Object; class ThreadData; class ThreadMain; -using ConditionVariable = std::condition_variable; -using Mutex = std::mutex; -using MutexLocker = std::unique_lock; - class Thread { public: diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 040954dd..23be995d 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include @@ -59,7 +60,7 @@ private: int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - libcamera::Mutex *lock); + libcamera::Mutex *lock) LIBCAMERA_TSA_REQUIRES(*lock); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg); From patchwork Mon Nov 29 11:44:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14842 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 B2752C324F for ; Mon, 29 Nov 2021 11:45:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63BD2605A0; Mon, 29 Nov 2021 12:45:15 +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="oAC0A7mX"; dkim-atps=neutral Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01CF2605A4 for ; Mon, 29 Nov 2021 12:45:12 +0100 (CET) Received: by mail-pj1-x102c.google.com with SMTP id gt5so12528501pjb.1 for ; Mon, 29 Nov 2021 03:45:11 -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=QyJp1wo8X/LrCsHfnNuW1F6S94xFr9aQXVRNt3MnHYY=; b=oAC0A7mXC9KmkaIKs1jhcacG/G7wD3TOSj3wCZcsoXgkVPcCllNmxOOnHzlLSA3bou wix0PcpRflq/C1gT8Qc2nQ/SwogoB5eQBNHu+a0XP3YE9u0k17C7Gb4yghJvZKvub6Mr aZmbQUSiblHP2laVaoSFIzGyqR9i64jdFR0hM= 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=QyJp1wo8X/LrCsHfnNuW1F6S94xFr9aQXVRNt3MnHYY=; b=C+wNjLnwCncw4mM1PGl+Ij/UWB0//Hz3C9Qgx4Lv/wqozMsERgO3cCaYhFWiQXwXAY TM+Ck6wOyz9K8JIMjzYFqbh/TeU6RLcdIYxmRWnzobQdCBJ2dwB/JhiCnNfmB+fChoyV vUqHYMcCHrCqnShfSI4ObWrcDkOafC+SaiXmGawU359Psdany065K404kxvsXBt3IEmy dAEDtK3nzyM9BsusPXL6SSfE9/v97+UWWDayuxCxSa+RRKyjYh9lHzvWa/5yOh0zMVy/ y5sH/1y4vFYqyYhNECNxWh4JIHCJnAg/nF648UaKvLPELx7T5X2tChSUN1ecUeyO9GSd /I+g== X-Gm-Message-State: AOAM532xTlLwWSkEt7ghZIbyfAu0EkctfgRf/1YLq6tgXyLbTgYvijvX Vn/iLHcC1zvFyS2TpyAyj6B9ZtLt4MwTWA== X-Google-Smtp-Source: ABdhPJzsQM1ti9ua2+qlLmRwvZ/pQ3FAYe63dM3/A8w4BVq1msp0aw0XbDGbDTAzpRvhpSEqe7m12Q== X-Received: by 2002:a17:902:db01:b0:141:ea12:2176 with SMTP id m1-20020a170902db0100b00141ea122176mr60157409plx.44.1638186310286; Mon, 29 Nov 2021 03:45:10 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:09 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:48 +0900 Message-Id: <20211129114453.3186042-7-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/11] android: camera_hal_manager: Add 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 applies clang thread safety annotation to CameraHalManager. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_hal_manager.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index c07684a1..5395d419 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -18,7 +17,8 @@ #include #include -#include +#include +#include #include @@ -54,14 +54,14 @@ private: void cameraAdded(std::shared_ptr cam); void cameraRemoved(std::shared_ptr cam); - CameraDevice *cameraDeviceFromHalId(unsigned int id); + CameraDevice *cameraDeviceFromHalId(unsigned int id) LIBCAMERA_TSA_REQUIRES(mutex_); std::unique_ptr cameraManager_; CameraHalConfig halConfig_; const camera_module_callbacks_t *callbacks_; - std::vector> cameras_; - std::map cameraIdsMap_; + std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::map cameraIdsMap_ LIBCAMERA_TSA_GUARDED_BY(mutex_); libcamera::Mutex mutex_; unsigned int numInternalCameras_; From patchwork Mon Nov 29 11:44:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14843 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 A8B44BF415 for ; Mon, 29 Nov 2021 11:45:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40537605B6; Mon, 29 Nov 2021 12:45:16 +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="WdMBIyoI"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C6A360592 for ; Mon, 29 Nov 2021 12:45:13 +0100 (CET) Received: by mail-pj1-x1032.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso13934218pjo.3 for ; Mon, 29 Nov 2021 03:45:13 -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=sp5Sw3uSiY5RflgCnmeAXEew7x/3MvLj60NFCnZsN6c=; b=WdMBIyoIVKUvVKq+ck48MAcl6/4QVFBZ+EpqA3c0gyz0tx61Ev9HUcakY0l3kIFPiZ WBnW9j9eaxJNzYxPi7prmKAwRj28GPD3jkTqqExNZnN1qhfq8dsbBFosOfDpBKOv4zIt knJVSLvIegRK8wJpYURiZy5cCi1FhZOn3XalQ= 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=sp5Sw3uSiY5RflgCnmeAXEew7x/3MvLj60NFCnZsN6c=; b=7HaecssufRu6L/eZOjN/f8fErRiJjSZKYhy9CCwg9TijOfkpOeJpcMCBtea2QaoOwU qcwLXUqTVUMvpVHiHe/K2VCaE7pbYee8mFul5N+pP4w/8MBvbKuYaRXAIXGWs2/NgHBU mwl56hYZuBSsy3UlDdpAA3JW2rYBlEpEzEbxMwi4BGJZPR+AM7QIKt5rH9p1saZQ6jQM 0AB8/iEqDKUxQpljpKyvQ82Otx+qTnvkelPLsekTAFBeJHBAw2+Xj0RPCwxI7M5cA0m2 zrxBd1UFIqVyKSMgkDD46rcE4+gExPNJ1XVtW+68Cmk++zgopOZMB3Cq6ISt60N/ttQ4 YOfQ== X-Gm-Message-State: AOAM532Gp241j4T2+IVcIZhwrsQPpwtA9YXQmbcYjjm+YDvUliEyZ2u7 vLLNbu8WzWPyO7E2SWQsrVCLc7ZTsjxpzA== X-Google-Smtp-Source: ABdhPJyrP1QpNkkgQx/GsNKndopbMOb+vK0r1dQ6MI/9XeTzlVaEp/OEVHRffpOa09zPAFko71/3sQ== X-Received: by 2002:a17:90a:bf8a:: with SMTP id d10mr37111102pjs.67.1638186311933; Mon, 29 Nov 2021 03:45:11 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:11 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:49 +0900 Message-Id: <20211129114453.3186042-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/11] android: camera_stream: Protect buffers initialization by mutex_ 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" The initialization on buffers_ in CameraStrean::configure() is not protected by mutex_. It is no problem because configure() is not invoked simultaneously while other functions are called. This protects it to keep the thread safety consistency for buffers access. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_stream.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 5a62b7cd..2181d094 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -125,6 +125,7 @@ int CameraStream::configure() if (ret < 0) return ret; + MutexLocker lock(*mutex_); /* Save a pointer to the reserved frame buffers */ for (const auto &frameBuffer : allocator_->buffers(stream())) buffers_.push_back(frameBuffer.get()); From patchwork Mon Nov 29 11:44:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14844 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 A417DBF415 for ; Mon, 29 Nov 2021 11:45:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5A87D605A6; Mon, 29 Nov 2021 12:45:20 +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="fguIXqxk"; dkim-atps=neutral Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F66E605BC for ; Mon, 29 Nov 2021 12:45:15 +0100 (CET) Received: by mail-pl1-x630.google.com with SMTP id u17so11932293plg.9 for ; Mon, 29 Nov 2021 03:45:15 -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=jkEnNVnDsKxPXQVrOr2o6e7y66s+KmMxUJ0aP0RkLt0=; b=fguIXqxkiDO7csnL7NPKuBJWH+fC17FvaRhnDe9fpaavOAMs/+91UdwosGUUAoeT+F uxpu47OYoymbmp068czsfJZsh/kINlIYkz/DneryP4zc8ZZGoj2sT+6KCGP4mhWtuqc6 ovWa/OmEQfs55x5Z4NZOVpIyxpdcra03RwhxA= 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=jkEnNVnDsKxPXQVrOr2o6e7y66s+KmMxUJ0aP0RkLt0=; b=b2PAPDAS10+XSDezxitVX0zDIlulBqc0bsEUvVwM+iDhq6txQvbqeZEqiXwbOo0lDU VekFOKPWVejeSzkVRUoqXkYuyu8Jh8Kq8kSvdifwxSjUtWWaDPuFjF1v5js+MqmmJuSQ 8g8wswaryw5n+IMEf2/bNRtG8EkKJLUnBeoXPdjNZcgyJLxvikJ9hxKlRz67T0WpAJmK SICeIPRgTmfDMuChdHKdQyhMSKt0313KXDFQ5s0mtQbqcMtvQo1Qlq0TkZ2BEE+IST9w KBjrRFFd1t3mlB+UKpMuY3Ss+x0db6FQzwDj5bMgNw6D2Pej6S8FoIumu1YzsbuHla9g BjOw== X-Gm-Message-State: AOAM532Qw6RWiczGhkG72pdIxnyRnfbyweaiD6DC7sUQ/1E4UoY04oZK EwpHmgsAf8W5Ax9zgGrfY8noPswYqM7s3A== X-Google-Smtp-Source: ABdhPJzRDB1WHt8A9OoyiFDFs38E5DMFVEv6zg0QRDWnwGToROPWLIGEfA6IO/mS2MMlwBxBe95qCw== X-Received: by 2002:a17:903:408c:b0:142:45a9:672c with SMTP id z12-20020a170903408c00b0014245a9672cmr59279113plc.7.1638186313714; Mon, 29 Nov 2021 03:45:13 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:13 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:50 +0900 Message-Id: <20211129114453.3186042-9-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/11] android: camera_stream: Add 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 applies clang thread safety annotation to CameraStream. Signed-off-by: Hirokazu Honda Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_stream.cpp | 2 +- src/android/camera_stream.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 2181d094..ae659808 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -275,7 +275,7 @@ void CameraStream::PostProcessorWorker::run() MutexLocker locker(mutex_); while (1) { - cv_.wait(locker, [&] { + cv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return state_ != State::Running || !requests_.empty(); }); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index c127a0e4..6737bd2d 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,13 +8,14 @@ #pragma once #include -#include #include #include #include +#include #include +#include #include #include @@ -155,8 +156,10 @@ private: libcamera::Mutex mutex_; libcamera::ConditionVariable cv_; - std::queue requests_; - State state_ = State::Stopped; + std::queue requests_ + LIBCAMERA_TSA_GUARDED_BY(mutex_); + + State state_ LIBCAMERA_TSA_GUARDED_BY(mutex_) = State::Stopped; }; int waitFence(int fence); @@ -168,7 +171,7 @@ private: const unsigned int index_; std::unique_ptr allocator_; - std::vector buffers_; + std::vector buffers_ LIBCAMERA_TSA_GUARDED_BY(mutex_); /* * The class has to be MoveConstructible as instances are stored in * an std::vector in CameraDevice. From patchwork Mon Nov 29 11:44:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14845 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 6677BC324F for ; Mon, 29 Nov 2021 11:45:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 02A60605A4; Mon, 29 Nov 2021 12:45:21 +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="gcl9fDDj"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3C5ED605B4 for ; Mon, 29 Nov 2021 12:45:17 +0100 (CET) Received: by mail-pg1-x52c.google.com with SMTP id j11so5912406pgs.2 for ; Mon, 29 Nov 2021 03:45:17 -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=3hURich/YKThkPSvS6bZkc/0Va6fPvKyJyaJXHVlALU=; b=gcl9fDDjUMS/XbVhHzWIAEX78M+2YfgLFXritbrcKha9Nmq0JLqSckxugrfbzk5e0N STzHlr2Yxu2sR0N4qdmFn4KDl11/okmK9a5CttClNRPHqp0OHTGMX5FQCiZZBO/+VzFY LbvHShWPex7h7NazG2EP2sFLneHxY+le6G4f4= 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=3hURich/YKThkPSvS6bZkc/0Va6fPvKyJyaJXHVlALU=; b=8KfUX8x5BUugUQn2bqt+3hhzGe6PTo/x8O4pXz1a3b3bw1l/5cNYDLVTZf0aufQAOj nDI2FFF3Isa5/1lz3HnLyQ4qpm+A05+PSXY0qdSH131dhNHQh4EQt8kRakRI2Zu6ppnz 6h08BuGcNwVAteyYq1g5yuiTPYoCV8m+bwGGTRPxZUHCCuZa+4nf7gHte0z1yfJd0f95 w11FnWJnWJ1JJUksZRgC4zhXvQCRkOBziuMyFiXdL0U0MLTJJPwHcvgWUfpWrt5Y+ZSb B0aYCB/hA/bvC13knSAY20azNmXK5epd29hKliLENxTKmStKMH4kCX6wzRPPwCGq70I8 i4Uw== X-Gm-Message-State: AOAM530+0LMUcwHS/1WLiIw6x7Dv+knW9+rbbBbjq1GyD3Rhw/SkEq64 wC4BFh8cHjNAsW8+/GkhoI8F8WmV7qz75w== X-Google-Smtp-Source: ABdhPJxupCe9ZR4ZpE9W171VeDKCZzpxv8wHOxpkzr2kd8ZYbw4siyJC9+H6dXt54nRyRTfI/6Usgg== X-Received: by 2002:a63:4c45:: with SMTP id m5mr22817120pgl.105.1638186315389; Mon, 29 Nov 2021 03:45:15 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:14 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:51 +0900 Message-Id: <20211129114453.3186042-10-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/11] android: camera_device: Fix variables access without protection 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 fixes the code accessing descriptors and Camera3RequestDescriptor::pendingStreamsToProcess_ without holding descriptorsMutex_ and Camera3RequestDescriptor::streamProcessMutex_ in CameraDevice. Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f2e0bdbd..59185e7f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -422,7 +422,11 @@ void CameraDevice::stop() worker_.stop(); camera_->stop(); - descriptors_ = {}; + { + MutexLocker descriptorsLock(descriptorsMutex_); + descriptors_ = {}; + } + streams_.clear(); state_ = State::Stopped; @@ -919,6 +923,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ FrameBuffer *frameBuffer = nullptr; int acquireFence = -1; + + MutexLocker lock(descriptor->streamsProcessMutex_); switch (cameraStream->type()) { case CameraStream::Type::Mapped: /* From patchwork Mon Nov 29 11:44:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14846 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 2D9AEBF415 for ; Mon, 29 Nov 2021 11:45:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D89D0605BB; Mon, 29 Nov 2021 12:45:21 +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="AgO1xoFp"; dkim-atps=neutral Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CA61660592 for ; Mon, 29 Nov 2021 12:45:18 +0100 (CET) Received: by mail-pg1-x534.google.com with SMTP id r5so15782194pgi.6 for ; Mon, 29 Nov 2021 03:45:18 -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=7N6nOACUKphc6ZSF1ybQg9PRBU9NHpQ5TXKsVKJlUr4=; b=AgO1xoFp0frMy8aSI94cAmJt0kmTcN4Tl0L6qF1b5ssclW+Reu143PVmChGBarWF6X usUWuLldiXUApbcTEQxfstxj4af3adz/IdTI00FNUXkCZ/emc367WO5Rq3Rvnjm0P2ZC XFUWJ2tnJ7U0NES99KBlm8I4Zputhf470N+1E= 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=7N6nOACUKphc6ZSF1ybQg9PRBU9NHpQ5TXKsVKJlUr4=; b=xf00C5i4mC52xzV+iKLXZMybdpPfiNr7UsoofrYmVCClaJfmv/HaJ+U5zkQ5GyfWLB d48Q0jJPc+TKCp+X2BRrirpm4+s3bW/1wBiPLS/TpLecC+DEUgnzvlDQtRHm1zlY72Vd igq6ftkDWIa8aEEY4lY+Ilw8ee9cW/TjtU/Ly2ATgvLH8uYz6hMAHvde5UDUVy1dLWZW QPF4rHre6UekkaPx6xEMhDT+Z2ppbpmRdqK98oiojM6GY47jchcF8Wdu6lHvgB9oFFou mrs43Spms/3kb8314gLJHLAZx8tFz+qgLd5UXiQQRHFu907SLd6LRgpbZeD/cm1YwawC NUJA== X-Gm-Message-State: AOAM531KSQ/te+F/MmGC+YgO2FsL5B+pOl+3R37TvSIHeGDUlosj5CrC FizVaL7y/rd3mj4ireSeBZQZjZ7InG2elg== X-Google-Smtp-Source: ABdhPJw3/2GP/3tKa+EYt+7fTsOt/ZfLcp8B13ejQhg2pd63SdMrjpc2yYOLtWiajnH1sHH14eMFaQ== X-Received: by 2002:a63:8248:: with SMTP id w69mr33777594pgd.342.1638186317093; Mon, 29 Nov 2021 03:45:17 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:16 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:52 +0900 Message-Id: <20211129114453.3186042-11-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/11] android: camera_device: Add 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 applies clang thread safety annotation to CameraDevice. Mutex and MutexLocker there are replaced with Mutex2 and MutexLocer2. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 2 -- src/android/camera_device.h | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 59185e7f..e7365175 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -932,7 +931,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * Request. */ LOG(HAL, Debug) << ss.str() << " (mapped)"; - descriptor->pendingStreamsToProcess_.insert( { cameraStream, &buffer }); continue; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 51fe7da2..2083dac1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -18,7 +17,8 @@ #include #include #include -#include +#include +#include #include #include @@ -83,7 +83,7 @@ private: Running, }; - void stop(); + void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer, @@ -95,8 +95,9 @@ private: void notifyError(uint32_t frameNumber, camera3_stream_t *stream, camera3_error_msg_code code) const; int processControls(Camera3RequestDescriptor *descriptor); - void completeDescriptor(Camera3RequestDescriptor *descriptor); - void sendCaptureResults(); + void completeDescriptor(Camera3RequestDescriptor *descriptor) + LIBCAMERA_TSA_EXCLUDES(descriptorsMutex_); + void sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_); void setBufferStatus(Camera3RequestDescriptor::StreamBuffer &buffer, Camera3RequestDescriptor::Status status); std::unique_ptr getResultMetadata( @@ -108,7 +109,7 @@ private: CameraWorker worker_; libcamera::Mutex stateMutex_; /* Protects access to the camera state. */ - State state_; + State state_ LIBCAMERA_TSA_GUARDED_BY(stateMutex_); std::shared_ptr camera_; std::unique_ptr config_; @@ -119,8 +120,9 @@ private: std::vector streams_; - libcamera::Mutex descriptorsMutex_; /* Protects descriptors_. */ - std::queue> descriptors_; + libcamera::Mutex descriptorsMutex_ LIBCAMERA_TSA_ACQUIRED_AFTER(stateMutex_); + std::queue> descriptors_ + LIBCAMERA_TSA_GUARDED_BY(descriptorsMutex_); std::string maker_; std::string model_; From patchwork Mon Nov 29 11:44:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14847 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 B6FF3BF415 for ; Mon, 29 Nov 2021 11:45:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E7FF605A5; Mon, 29 Nov 2021 12:45:24 +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="iqw5Ia1h"; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 90402605BC for ; Mon, 29 Nov 2021 12:45:20 +0100 (CET) Received: by mail-pg1-x529.google.com with SMTP id r5so15782268pgi.6 for ; Mon, 29 Nov 2021 03:45:20 -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=JedrOwQA5kD3N95srlI/iWKZv5HXuMwvL92/B73i6ws=; b=iqw5Ia1hIfxXBuAIRIfkIv+szDpJ1CELjvJBSehHFECNUWpKeIPmY8GP406VXqQJA0 W55yMgO4Gj1xEOJUGMyng0IqNxC6fS5DdS8CkyF1nSjaDYYfqWiRfF/ZRtiMBrjtV+to ef+U7AymzWl84Ril3haDf9S/oyHpIiBNUSylg= 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=JedrOwQA5kD3N95srlI/iWKZv5HXuMwvL92/B73i6ws=; b=Q5l5BLI9miqTFZZsO8fEmY10Hv+8y1llF6z5yLsesaA7e6j7ahxGa8++WpDOU64/jP 2gHMq9ixdWEMowSGGsjInUFP/Z9pq6dq26VLciTKMsV0oIQ6TJJ6t1a7FIKz7cIvuKm2 S0X6z0yN7Phq6088hG2gP2nyk1WUYBRk8YODO6ySX6DWtepv+gjBygrXDbetHecVNIjw Vh0Wc7083llYbgBTMLRWge88tCaUHQ49oIWwsf62ymXPBx6nnrX9prNBTKHyIfpwvJHO 0OOLqOD3/8qp7x5ZS2hcQHLs4Uj4JfkteRjZdCPfgJDhHEewUkPE6W18AfYxjMQzyDew HL7w== X-Gm-Message-State: AOAM533XLJ5BfPOXsja7bYGlL3SaiaEM60R0oO1DQbRXPhUyaMXBRnM6 f4gOskZENNHE6GwpKSHMqyxuER5q/bQm4w== X-Google-Smtp-Source: ABdhPJxHLDgAWYV3szmQO+O1XR8VdQ2FTgRu0Fb2OGCFy8XD2Qj5j6gVkgDvK1MTWclqhUAi6UWwoQ== X-Received: by 2002:a05:6a00:17a4:b0:49f:c0c0:3263 with SMTP id s36-20020a056a0017a400b0049fc0c03263mr39278900pfg.81.1638186318944; Mon, 29 Nov 2021 03:45:18 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:f254:cda9:46e8:17b7]) by smtp.gmail.com with ESMTPSA id hg4sm17951966pjb.1.2021.11.29.03.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:45:18 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:53 +0900 Message-Id: <20211129114453.3186042-12-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211129114453.3186042-1-hiroh@chromium.org> References: <20211129114453.3186042-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/11] android: camera_request: Add 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 applies clang thread safety annotation to Camera3RequestDescriptor. Mutex and MutexLocker there are replaced with Mutex2 and MutexLocer2. Signed-off-by: Hirokazu Honda Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_request.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 88d501a8..dfdc3324 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -12,7 +12,8 @@ #include #include -#include +#include +#include #include #include @@ -57,7 +58,8 @@ public: }; /* Keeps track of streams requiring post-processing. */ - std::map pendingStreamsToProcess_; + std::map pendingStreamsToProcess_ + LIBCAMERA_TSA_GUARDED_BY(streamsProcessMutex_); libcamera::Mutex streamsProcessMutex_; Camera3RequestDescriptor(libcamera::Camera *camera,