From patchwork Wed Dec 1 07:53:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14940 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 D8E63BF415 for ; Wed, 1 Dec 2021 07:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91E6B60720; Wed, 1 Dec 2021 08:53:57 +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="coy76HLG"; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6825260592 for ; Wed, 1 Dec 2021 08:53:56 +0100 (CET) Received: by mail-pl1-x633.google.com with SMTP id z6so17037545plk.6 for ; Tue, 30 Nov 2021 23:53:56 -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=xwRdoC8kZYbR0aPkKBfZglVVOjxO3iRVsfRtx3VIt7k=; b=coy76HLGSL2zUqdPsbxA0fMrjlSlhCDD66GBCGzpgnj51qDQMUJTkd0NWEYbFmfhny /4bCC96KaQpsNb27Gtb2DBO4XHjcccGt0cE6WJlAbcwNgzgcGmLtc6YUdW148gwpCU4C C4XViBc0nyfIiWkGUqCJpDW5Ekkkl9ak9e0VY= 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=xwRdoC8kZYbR0aPkKBfZglVVOjxO3iRVsfRtx3VIt7k=; b=FuGj29MiqGcIQrX3jl/mdJxeP9MqpsX+jdW8ymP5UmPBREH46mJhg1l4CE08QmvyEt rquljHuxuQoOPQXSOVbvTINnQEbV+fo4OdV5a/3I8npGDjpvFlnNuC2nMNI5SKaed4YU Ki76FJtJHAbFm7pfDdVvaEu85nnSvBCIkYtY13Vc97G2VAQVc8hOY9RhzFtWmj5VBY8k iQ+CJfoDZe40ucOgRsMR6Qlt9c+DjRgwipP6jkHWwJUtDmpomouWA077E9HbDZcKaVYv ckbNQ5SnSjWysPiRcJO8umgg8F+/HGMYU2In33Z9SBhkibA/E/tFUg6kM5m8hZ3d2EXz q9/A== X-Gm-Message-State: AOAM532xatGEgVe5HJJ7PeV+dYuJMg8OwV+PkD59FqPm5gMSeG0go6CV +dGvnVmk3t47jMtcIb+RLFqe17XE1NDM4g== X-Google-Smtp-Source: ABdhPJzAARZlfgqRb28VFM3vBT/wxNXpNKJjBv0bUUD0+1NfEmI1tlCgwxcAwS2euguY0x3anHM+zQ== X-Received: by 2002:a17:902:9b8f:b0:142:7999:67fb with SMTP id y15-20020a1709029b8f00b00142799967fbmr5599023plp.24.1638345234354; Tue, 30 Nov 2021 23:53:54 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:53:53 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:36 +0900 Message-Id: <20211201075348.3121186-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 v5: * 05/12: Address comments from Laurent 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 | 56 +++++++++ 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, 332 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