From patchwork Tue Nov 30 15:55: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: 14897 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 8289FBF415 for ; Tue, 30 Nov 2021 15:56:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A028E6071B; Tue, 30 Nov 2021 16:56: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="OLBPLAPw"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 35B27605C4 for ; Tue, 30 Nov 2021 16:56:09 +0100 (CET) Received: by mail-pg1-x532.google.com with SMTP id s37so10567583pga.9 for ; Tue, 30 Nov 2021 07:56:09 -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=SWpHN9d0Ewfikdi4B4yPAUP0Jnd4BjI4uRqAYVw1fdI=; b=OLBPLAPwt/+iCpBBXTopg9mLRxPp+kklnWuc2awTIaSBkVnL5t0epXXnz4RijSAouq HJpNz+qf+j8RxWrK8yxfWgkwFQIm+XnaxwYXsrWn6uxLkCndqQAhdBCXgnkaUvr/YmUD xPhzATCX4Cj2XAfGrOWus3UmzZ3pXyK+tfgpg= 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=SWpHN9d0Ewfikdi4B4yPAUP0Jnd4BjI4uRqAYVw1fdI=; b=x5sVU2CZ3mTr8O+DBxm2prBkF5JeBAtQ6JDONEipcrhRiEQyu+eXD849ES2quYfrIi o+HVNCkcKq6ECzJELIDKUTqIhcjtaEIuDSr42EYIyfZqJpu34/N2WQNVQKUMaEUhNa/t 25dYadX2hc4hWL9fFutirGa6AaStjnyQGGSTeDOu417OxMVFmVDTZ2PjDNBgvAcZgSPa Cp9wdj2S0VQtsmmxP0Dqi9wGd1o1YEv9yyS7+Vd8pfy6porcGoaUFJsKvjFTLwOEL7pR AfRcOZ5cLQzfI+PCYr5yw8oEJ5z+JFjUHQMzqzvCmVAvxDDD4TvW/nzmRGo7SYw/ESLo 7aQg== X-Gm-Message-State: AOAM530okAAAk6FFqXL8pqjksrLwfvswAlXyLFDwYSuXGJoSLG7yBiVq vCL3Ydxk+eCHHEI9kmhGKyhyEb1OJU385g== X-Google-Smtp-Source: ABdhPJy1LkmFM4KM38nriTkYDGcMN/Gp4qtKAJ1YkMqEk9m76O5H7c/BlCJowrcBcqVEUC+TwABy/w== X-Received: by 2002:a63:e04f:: with SMTP id n15mr41446070pgj.31.1638287767088; Tue, 30 Nov 2021 07:56:07 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:06 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:48 +0900 Message-Id: <20211130155600.2203123-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 v3: * Addresses comments from Laurent * 05/12: Add documentation about Mutex, MutexLocker and ConditionVariable * 06/12: Clean up include headers of thread.h and mutex.h 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 | 131 ++++++++++++++++++++ include/libcamera/base/semaphore.h | 6 +- include/libcamera/base/thread.h | 4 - include/libcamera/base/thread_annotations.h | 80 ++++++++++++ meson.build | 1 + src/android/camera_device.cpp | 9 +- src/android/camera_device.h | 18 +-- src/android/camera_hal_manager.h | 14 +-- src/android/camera_request.h | 8 +- src/android/camera_stream.cpp | 15 +-- src/android/camera_stream.h | 16 +-- src/libcamera/base/meson.build | 1 + src/libcamera/base/mutex.cpp | 121 ++++++++++++++++++ src/libcamera/base/semaphore.cpp | 1 - src/libcamera/base/signal.cpp | 3 +- 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 | 5 +- 21 files changed, 399 insertions(+), 68 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