From patchwork Mon Nov 29 11:44:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14836 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 F1BB0BF415 for ; Mon, 29 Nov 2021 11:45:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CA52605A1; Mon, 29 Nov 2021 12:45:03 +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="mnKWEF/6"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E16E60592 for ; Mon, 29 Nov 2021 12:45:02 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id gt5so12528102pjb.1 for ; Mon, 29 Nov 2021 03:45:01 -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=pVtl+48kGHuzFX/w53S0P3Pm25h8VzfbAYUT+V+PZpw=; b=mnKWEF/6yuOLf1TvLsHdnJoj89uv60WcnU6T/9UtKJQ517mL/HL61Umnv28dG1TZN1 3UCg31Y2uK2U3drosFoW3O9lRrUSblsACVQt7YyZu/dXZ4g6FvFirb2hmk63l3X7NL3t 6Z13OEYDKz196Rm8z5jcMXvPEtTFvN7hhOuC8= 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=pVtl+48kGHuzFX/w53S0P3Pm25h8VzfbAYUT+V+PZpw=; b=BjBDxHNx/SYeIYaAHHTanHvPxL0jFSG1kB4JFnCLV2zVijAYQtbmYL9181ObjaeAfa H4K20SPhwqMgoAiaRs14trhOr0uEtzRtLY62qijG8+7YmzeSEn8jN5F9RaC1+/n5zMj/ aaXDHwm7l/qtFK3JG+wIVOS6qzDLDeDISdZZV2zu22Y+H/19EFGoCRgFKfXDq+WNkFXn cZEJx58rsitw9tpuTj/DbM5eQnYYV9Un6sb8XVrEnCa7QSTknExAs86OWQkBQXm+vwRX r2ZRLJa0BBcWudWoGeTYM8CQ48PRuTStDqh7GsDEQw3wjeAF9NOGsRex2GuxSl5y1en4 r6Mw== X-Gm-Message-State: AOAM532QL56h+Qi6NXf4ziCJ/+URxj1P8nE0yHoqLJ35oUTrl00umkk6 bp2S7r/GrG03MLYyZja99f1NqpXaE3UiQw== X-Google-Smtp-Source: ABdhPJw0sTltD0t2zDgUMr55GaidLWBcoB8+t5kAwpHnEDNuxzRcsoZMJyf96iuDFdoGMW9Et9B+3w== X-Received: by 2002:a17:90b:512:: with SMTP id r18mr37157940pjz.64.1638186300114; Mon, 29 Nov 2021 03:45:00 -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.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 03:44:59 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 20:44:42 +0900 Message-Id: <20211129114453.3186042-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 00/11] 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 v2: - Introduce ConditionVariable - Consolidate std::mutex/std::unique_lock and Mutex/MutexLocker - Replace Mutx and MutexLocker with new classes, not having duplicated classes - Separate code fix patches from thread annotation patches Hirokazu Honda (11): 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 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 | 127 ++++++++++++++++++++ include/libcamera/base/semaphore.h | 4 +- include/libcamera/base/thread.h | 5 +- include/libcamera/base/thread_annotations.h | 80 ++++++++++++ meson.build | 1 + src/android/camera_device.cpp | 10 +- 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/thread.cpp | 3 +- src/libcamera/camera_manager.cpp | 3 +- src/v4l2/v4l2_camera.h | 4 +- src/v4l2/v4l2_camera_proxy.cpp | 8 +- src/v4l2/v4l2_camera_proxy.h | 5 +- 17 files changed, 269 insertions(+), 54 deletions(-) create mode 100644 include/libcamera/base/mutex.h create mode 100644 include/libcamera/base/thread_annotations.h --- 2.34.0.rc2.393.gf8c9666880-goog