{"id":14942,"url":"https://patchwork.libcamera.org/api/patches/14942/?format=json","web_url":"https://patchwork.libcamera.org/patch/14942/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211201075348.3121186-3-hiroh@chromium.org>","date":"2021-12-01T07:53:38","name":"[libcamera-devel,v5,02/12] android: Consolidate mutex classes to Mutex and MutexLocker","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8e9a65f0b91e840aeed9a8161b284c60e2933c36","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14942/mbox/","series":[{"id":2791,"url":"https://patchwork.libcamera.org/api/series/2791/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2791","date":"2021-12-01T07:53:36","name":"Introduce clang thread safety annotations","version":5,"mbox":"https://patchwork.libcamera.org/series/2791/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14942/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14942/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D0C08BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Dec 2021 07:54:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82B4260718;\n\tWed,  1 Dec 2021 08:54:01 +0100 (CET)","from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com\n\t[IPv6:2607:f8b0:4864:20::1034])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BC51A60710\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 08:53:59 +0100 (CET)","by mail-pj1-x1034.google.com with SMTP id gt5so17337192pjb.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 23:53:59 -0800 (PST)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:3892:a049:59ba:c772])\n\tby smtp.gmail.com with ESMTPSA id\n\tl9sm3500848pfu.55.2021.11.30.23.53.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 30 Nov 2021 23:53:57 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"BvX48i06\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=hri0Xm34PsgBbaDCXWbRIaQJpAoLrbjERv7g2d7844k=;\n\tb=BvX48i06h4MxzzEwpkr2M6jb3Gb5DN2qJSTfniEIiP4OtbryLbNyHoc1DfrT1+nItO\n\t0LG+hlhVUA7KxJ4iOSRi63CC6tvouPaEigmLXOHG0E/vevUllSMKQ8rcd991T2kQ2ory\n\tDKP182njMLwdbHLv+K8HtP1UW+kyeC6gAGCas=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=hri0Xm34PsgBbaDCXWbRIaQJpAoLrbjERv7g2d7844k=;\n\tb=zv0LP85qKXXI81yyaYtiQwE2FQXHyB+gx+r0pvu9aCb8KFFe4MX4dZWv7A/nyY5YfH\n\tmF7DPpb5qk03/ITcSmw0opnKbF92qPQxVHhzmSmFwJOmOkH/nKfN021ntMaPlFbmTEiR\n\tLbjHUANZfreDndcwrvDwPon9x11l+zMIWHDsDdlbjYn3Ln908FJBWW/ptqCvb7kkxibs\n\tf4lTF2e7QwHMvUvZMhloKbtBP3oRKo5KO6SUcZbXIcsrv7stPYXF07HNKrzmxEmQd5wd\n\tjAONQay1ek/l8ZFk/jtU2NkRcDj2NvIFbSl3W0EP26MD9ajdllrJlrPck7hKeYmOtgnB\n\t+bxQ==","X-Gm-Message-State":"AOAM530cI9ckcoTcjvRDlnWZ7aH56rex291YqT6Wx6HgEDomOtZAFdTi\n\tEh1NG2y9T/xZn5VaVI2q3F4AKIeT2D6/KQ==","X-Google-Smtp-Source":"ABdhPJwXOGnGUkAQcGrVELBSEB2SXp3dzc1v+ibpGTdLHDGPaj+VXq8TAC8vQxEQ2+3iVpvwhf0EGA==","X-Received":"by 2002:a17:90a:db81:: with SMTP id\n\th1mr5628120pjv.46.1638345237874; \n\tTue, 30 Nov 2021 23:53:57 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  1 Dec 2021 16:53:38 +0900","Message-Id":"<20211201075348.3121186-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.34.0.rc2.393.gf8c9666880-goog","In-Reply-To":"<20211201075348.3121186-1-hiroh@chromium.org>","References":"<20211201075348.3121186-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 02/12] android: Consolidate mutex\n\tclasses to Mutex and MutexLocker","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"std::mutex and std::unique_lcok are used in android directories,\nmixing Mutex and MutexLocker. This consolidates them to Mutex\nand MutexLocker.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.h      |  1 -\n src/android/camera_hal_manager.h |  7 ++-----\n src/android/camera_request.h     |  4 ++--\n src/android/camera_stream.cpp    | 12 ++++++------\n src/android/camera_stream.h      |  3 +--\n 5 files changed, 11 insertions(+), 16 deletions(-)","diff":"diff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 51fe7da2..bda0b376 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -9,7 +9,6 @@\n \n #include <map>\n #include <memory>\n-#include <mutex>\n #include <queue>\n #include <vector>\n \ndiff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\nindex 192f2fc5..cc310f90 100644\n--- a/src/android/camera_hal_manager.h\n+++ b/src/android/camera_hal_manager.h\n@@ -8,7 +8,6 @@\n #pragma once\n \n #include <map>\n-#include <mutex>\n #include <stddef.h>\n #include <tuple>\n #include <vector>\n@@ -18,6 +17,7 @@\n #include <system/camera_metadata.h>\n \n #include <libcamera/base/class.h>\n+#include <libcamera/base/thread.h>\n \n #include <libcamera/camera_manager.h>\n \n@@ -44,9 +44,6 @@ public:\n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager)\n \n-\tusing Mutex = std::mutex;\n-\tusing MutexLocker = std::unique_lock<std::mutex>;\n-\n \tstatic constexpr unsigned int firstExternalCameraId_ = 1000;\n \n \tCameraHalManager();\n@@ -64,7 +61,7 @@ private:\n \tconst camera_module_callbacks_t *callbacks_;\n \tstd::vector<std::unique_ptr<CameraDevice>> cameras_;\n \tstd::map<std::string, unsigned int> cameraIdsMap_;\n-\tMutex mutex_;\n+\tlibcamera::Mutex mutex_;\n \n \tunsigned int numInternalCameras_;\n \tunsigned int nextExternalCameraId_;\ndiff --git a/src/android/camera_request.h b/src/android/camera_request.h\nindex f3cb6d64..88d501a8 100644\n--- a/src/android/camera_request.h\n+++ b/src/android/camera_request.h\n@@ -9,10 +9,10 @@\n \n #include <map>\n #include <memory>\n-#include <mutex>\n #include <vector>\n \n #include <libcamera/base/class.h>\n+#include <libcamera/base/thread.h>\n \n #include <libcamera/camera.h>\n #include <libcamera/framebuffer.h>\n@@ -58,7 +58,7 @@ public:\n \n \t/* Keeps track of streams requiring post-processing. */\n \tstd::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_;\n-\tstd::mutex streamsProcessMutex_;\n+\tlibcamera::Mutex streamsProcessMutex_;\n \n \tCamera3RequestDescriptor(libcamera::Camera *camera,\n \t\t\t\t const camera3_capture_request_t *camera3Request);\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex 9023c13c..5a62b7cd 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -119,7 +119,7 @@ int CameraStream::configure()\n \n \tif (type_ == Type::Internal) {\n \t\tallocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n-\t\tmutex_ = std::make_unique<std::mutex>();\n+\t\tmutex_ = std::make_unique<Mutex>();\n \n \t\tint ret = allocator_->allocate(stream());\n \t\tif (ret < 0)\n@@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer()\n \tif (!allocator_)\n \t\treturn nullptr;\n \n-\tstd::lock_guard<std::mutex> locker(*mutex_);\n+\tMutexLocker locker(*mutex_);\n \n \tif (buffers_.empty()) {\n \t\tLOG(HAL, Error) << \"Buffer underrun\";\n@@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer)\n \tif (!allocator_)\n \t\treturn;\n \n-\tstd::lock_guard<std::mutex> locker(*mutex_);\n+\tMutexLocker locker(*mutex_);\n \n \tbuffers_.push_back(buffer);\n }\n@@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces\n CameraStream::PostProcessorWorker::~PostProcessorWorker()\n {\n \t{\n-\t\tlibcamera::MutexLocker lock(mutex_);\n+\t\tMutexLocker lock(mutex_);\n \t\tstate_ = State::Stopped;\n \t}\n \n@@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker()\n void CameraStream::PostProcessorWorker::start()\n {\n \t{\n-\t\tlibcamera::MutexLocker lock(mutex_);\n+\t\tMutexLocker lock(mutex_);\n \t\tASSERT(state_ != State::Running);\n \t\tstate_ = State::Running;\n \t}\n@@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run()\n \n void CameraStream::PostProcessorWorker::flush()\n {\n-\tlibcamera::MutexLocker lock(mutex_);\n+\tMutexLocker lock(mutex_);\n \tstate_ = State::Flushing;\n \tlock.unlock();\n \ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex e4808369..adb5a37d 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -8,7 +8,6 @@\n #pragma once\n \n #include <memory>\n-#include <mutex>\n #include <queue>\n #include <vector>\n \n@@ -173,7 +172,7 @@ private:\n \t * The class has to be MoveConstructible as instances are stored in\n \t * an std::vector in CameraDevice.\n \t */\n-\tstd::unique_ptr<std::mutex> mutex_;\n+\tstd::unique_ptr<libcamera::Mutex> mutex_;\n \tstd::unique_ptr<PostProcessor> postProcessor_;\n \n \tstd::unique_ptr<PostProcessorWorker> worker_;\n","prefixes":["libcamera-devel","v5","02/12"]}