From patchwork Fri Oct 29 04:14:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14410 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 D291FBF415 for ; Fri, 29 Oct 2021 04:14:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8CA47600C3; Fri, 29 Oct 2021 06:14:39 +0200 (CEST) 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="MxFZQXfS"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3123D600C1 for ; Fri, 29 Oct 2021 06:14:37 +0200 (CEST) Received: by mail-pg1-x52b.google.com with SMTP id q187so8697058pgq.2 for ; Thu, 28 Oct 2021 21:14:37 -0700 (PDT) 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=L3Ks0SBFgrAtnuHoUek3d3iZpn1ML52IY5W1kRp0HGs=; b=MxFZQXfS0F1tVQWbIPlLxQ5Ir3QngnyCxetV7mlfGUYa5+8e5Fw9cD8RlPQJvudrCg /aXXCaEZTyf1Xsl3/MMAhIt1LPFyDMf9GwRizlMT4v+LQraDoz+A/Q1rT1jrC2wy0HaT gK6wxHQ00PcY51hHeFHDtVL0MMJcj4CyKRjug= 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=L3Ks0SBFgrAtnuHoUek3d3iZpn1ML52IY5W1kRp0HGs=; b=azXDlUaxCoqVblvekQdneeJrFfdS4j3va3pZjq76Ssls90yyRO/lZ0Gjj0un0xK+dO xgySy4WWtC+o4eyls17YZhw651CB6bIY9IPDU5AheSipFXD0SN+276kFA2CAaJvB6REz bn09h0SbGZ5fEZ3vTf3eA8Jk9Nhf/0eLsZ4LP9cPLcOE9kWyxwwR7c1CfBPlI2lHlwQZ 5gPfifF3WwfHt4OHuqN44ESWrPqsjaQOk3phITeeTOmX5PQWiAhdGcInwtVjTJrx44ay xipGtzmNlzBkvUqM+qKeY8QngP8HvtA+qVkHkH1T6jHLrVaqGOIRFR8RBAMYSWtGq1pS gyYg== X-Gm-Message-State: AOAM532qgZGmNd2m5TJ6FcOvFgKPSTGv6+MJ/kweMFCLjSNU07JUU7HY ZiKfTG3j4crUQ+idhDCg4cBl5EwgqarLBA== X-Google-Smtp-Source: ABdhPJyCnd4t5M/pJVzfiKdirPIjRkUUfgiUsInyH1VAiGxbz4ob93J1SLVRGzhyknXCtgi+ODBytg== X-Received: by 2002:aa7:9099:0:b0:44c:a3b5:ca52 with SMTP id i25-20020aa79099000000b0044ca3b5ca52mr8342615pfa.85.1635480875319; Thu, 28 Oct 2021 21:14:35 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:fd56:8786:5663:b946]) by smtp.gmail.com with ESMTPSA id 11sm4826714pfl.41.2021.10.28.21.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 21:14:34 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 29 Oct 2021 13:14:21 +0900 Message-Id: <20211029041424.1430886-4-hiroh@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211029041424.1430886-1-hiroh@chromium.org> References: <20211029041424.1430886-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 3/6] 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. 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_hal_manager.cpp | 10 +++++----- src/android/camera_hal_manager.h | 14 ++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 5f7bfe26..26715a5f 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -75,7 +75,7 @@ int CameraHalManager::init() std::tuple CameraHalManager::open(unsigned int id, const hw_module_t *hardwareModule) { - MutexLocker locker(mutex_); + MutexLocker2 locker(mutex_); if (!callbacks_) { LOG(HAL, Error) << "Can't open camera before callbacks are set"; @@ -103,7 +103,7 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) bool isCameraExternal = false; bool isCameraNew = false; - MutexLocker locker(mutex_); + MutexLocker2 locker(mutex_); /* * Each camera is assigned a unique integer ID when it is seen for the @@ -198,7 +198,7 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) void CameraHalManager::cameraRemoved(std::shared_ptr cam) { - MutexLocker locker(mutex_); + MutexLocker2 locker(mutex_); auto iter = std::find_if(cameras_.begin(), cameras_.end(), [&cam](const std::unique_ptr &camera) { @@ -257,7 +257,7 @@ int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info) if (!info) return -EINVAL; - MutexLocker locker(mutex_); + MutexLocker2 locker(mutex_); CameraDevice *camera = cameraDeviceFromHalId(id); if (!camera) { @@ -280,7 +280,7 @@ void CameraHalManager::setCallbacks(const camera_module_callbacks_t *callbacks) { callbacks_ = callbacks; - MutexLocker locker(mutex_); + MutexLocker2 locker(mutex_); /* * Some external cameras may have been identified before the callbacks_ diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 3f6d302a..9b8c3a1f 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -8,7 +8,6 @@ #define __ANDROID_CAMERA_MANAGER_H__ #include -#include #include #include #include @@ -18,6 +17,8 @@ #include #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(); @@ -56,15 +54,15 @@ private: void cameraAdded(std::shared_ptr cam); void cameraRemoved(std::shared_ptr cam); - CameraDevice *cameraDeviceFromHalId(unsigned int id); + CameraDevice *cameraDeviceFromHalId(unsigned int id) REQUIRES(mutex_); std::unique_ptr cameraManager_; CameraHalConfig halConfig_; const camera_module_callbacks_t *callbacks_; - std::vector> cameras_; - std::map cameraIdsMap_; - Mutex mutex_; + std::vector> cameras_ GUARDED_BY(mutex_); + std::map cameraIdsMap_ GUARDED_BY(mutex_); + libcamera::Mutex2 mutex_; unsigned int numInternalCameras_; unsigned int nextExternalCameraId_;