From patchwork Wed Dec 1 07:07:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14926 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 4ACADBF415 for ; Wed, 1 Dec 2021 07:07:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BB7460723; Wed, 1 Dec 2021 08:07:38 +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="Gbx7cCYs"; 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 A297960592 for ; Wed, 1 Dec 2021 08:07:36 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id l190so22627026pge.7 for ; Tue, 30 Nov 2021 23:07:36 -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:mime-version :content-transfer-encoding; bh=04k+W1XnrWIHBeI6ZH/b/JfE7ejsgYLrldfC+AWpxao=; b=Gbx7cCYsg3UgxNDEpoFeRNr/1CM4T29uN6BGZkvhItqCeL7a2ZqJrKZQaLBB4MJOpu 8vF6Vp8AkoF9OVXrgh8v5W8is2i3izCyWVQXUpZlF2Y4euAKcdm8mRKPux8rvOjl3egQ PBKV6snBRcBYyarLXLShJ9Um1AAAyNYSysXPo= 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:mime-version :content-transfer-encoding; bh=04k+W1XnrWIHBeI6ZH/b/JfE7ejsgYLrldfC+AWpxao=; b=sydsTjU+0NKxDPSJybMAvjit1ozDlbW11+ZzWeCFvaPXd84dWoCHyr+UEsNJkJcfVx cutllHkwiES1sZ0ZgQw/aaVIDuZ0b/AZRFxyrsIDQTTkql8rmyij4oq6UYDMCGZG/23D worPbgZOcnflZgwMQlHvrBLcLtaOk8qLJ2Htz6f2+HfdjdNMjReOu0o/x11xJP+n4/Cr HM6jF61Y7O86JYgceIj713msmBd1/sroglIm92xe6Ul8WyHgGCF52UXF80UDlv05mbRK LrHgOO5VeMoWzndIKmg2jp0wA45vxom++Zyl/KQxGgE+UDvD/SLIt6NkFUUhYrWWuJkd YZkw== X-Gm-Message-State: AOAM5302tpvMBcxzTYTw8DsRG+oXpbVK+d2IdlEcr4YC7TL3qdx7nk3I M47IcGJLsnUHE4KmMiGyB1BMHlo70xAfqw== X-Google-Smtp-Source: ABdhPJyLLTHUKQ5+I2Aithsr1iGgU13bePizY+EyZ7f9UvAWdjZC2x7npCn/YS8Sd0mtwFkCyDW4LA== X-Received: by 2002:aa7:9207:0:b0:4a4:f59a:9df with SMTP id 7-20020aa79207000000b004a4f59a09dfmr4131987pfo.63.1638342454570; Tue, 30 Nov 2021 23:07:34 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:34 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:16 +0900 Message-Id: <20211201070728.3114247-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 00/12] Introduce clang 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 introduces clang thread safety annotations and applies it to libcamera Android HAL adaptation layer. It is necessary to add new classes that wrap std::mutex, std::unique_lock and std::condition_variable with the annotations. It is because no C++ standard library annotates all the mutex classes today. libstdc++ doesn't annotate any classes. libc++ annotates for std::mutex, std::lock_guard and std::scoped_lock, but doesn't for std::unique_lock. Therefore it is possible to use std::mutex if libc++ is used. Althoug I don't do so In this patch series because the existing code using std::mutex is not annotated yet. Document: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html Change in v4: * Address comments from Laurent * Remove thread_annotations.h include where mutex.h is included * 05/12: Remove document about members of Mutex classes Hirokazu Honda (12): libcamera: base: Introduce ConditionVariable android: Consolidate mutex classes to Mutex and MutexLocker v4l2: Consolidate mutex classes to Mutex and MutexLocker libcamera: base: Add thread safety annotation macros libcamera: base: Add mutex classes with thread safety annotations libcamera: Correct include headers for Mutex classes android: camera_hal_manager: Add thread safety annotation android: camera_stream: Protect buffers initialization by mutex_ android: camera_stream: Add thread safety annotation android: camera_device: Fix variables access without protection android: camera_device: Add thread safety annotation android: camera_request: Add thread safety annotation include/libcamera/base/meson.build | 2 + include/libcamera/base/mutex.h | 132 ++++++++++++++++++++ include/libcamera/base/semaphore.h | 7 +- include/libcamera/base/thread.h | 4 - include/libcamera/base/thread_annotations.h | 80 ++++++++++++ meson.build | 1 + src/android/camera_device.cpp | 10 +- src/android/camera_device.h | 17 +-- src/android/camera_hal_manager.h | 13 +- src/android/camera_request.h | 7 +- src/android/camera_stream.cpp | 15 +-- src/android/camera_stream.h | 15 +-- src/libcamera/base/meson.build | 1 + src/libcamera/base/mutex.cpp | 65 ++++++++++ src/libcamera/base/semaphore.cpp | 1 - src/libcamera/base/signal.cpp | 2 +- src/libcamera/base/thread.cpp | 14 +-- src/libcamera/camera_manager.cpp | 4 +- src/v4l2/v4l2_camera.h | 6 +- src/v4l2/v4l2_camera_proxy.cpp | 8 +- src/v4l2/v4l2_camera_proxy.h | 4 +- 21 files changed, 341 insertions(+), 67 deletions(-) create mode 100644 include/libcamera/base/mutex.h create mode 100644 include/libcamera/base/thread_annotations.h create mode 100644 src/libcamera/base/mutex.cpp --- 2.34.0.rc2.393.gf8c9666880-goog