From patchwork Thu Feb 4 09:34:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 11132 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 31B7EBD162 for ; Thu, 4 Feb 2021 09:35:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1582261418; Thu, 4 Feb 2021 10:35:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="PiO+gqTT"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5A5D861402 for ; Thu, 4 Feb 2021 10:35:03 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id d16so2608176wro.11 for ; Thu, 04 Feb 2021 01:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=abXjeJ8fOOsHiqXb1xOtDpFUgjWFPczUiRCmefqAMUI=; b=PiO+gqTTLFmGgUibscrhewkUs73YtI9ZyQY5l2AMekf7OZ0q1qzlbgaNX6NqKmaPOA oQHQW9Ub2HoG0zZhiWAr2jQFg6/VRtq/ORwI9Yclb4C2xD23FIiVeZ/h9dCa2fntOX/3 XKm1sd4r5AarEYQUjKAMsQkfkJQ+MfkTdwIVHI9dUmSze1VovQzGrAdPAo5LxMM8a2ug C1wog48FNMrTPREu1HrXSOHVSjVzNRAGj0EPYrie3gJucwpuAKaqN6U+kQ01H+BcNrk2 bRAkmRCDqcaJeV6v9wndlUiHp+1hWF0L99qUvSAekVyodLBePo0BzUjcNOunwnFU7eO0 M8zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=abXjeJ8fOOsHiqXb1xOtDpFUgjWFPczUiRCmefqAMUI=; b=icQzt6iBKoTSDsgilxW0RD5RERl9ySfLyawSZ5D39iGujL1deUz9euSNP6fDZKjKg8 eF4C/EaiYhETOaiziB6WI2o9aqC12oqu0tJmN2edTaqod+q8ZSPydChbu9EMnYwr3xAE 8nh4+cJPM61Pd/kBi2G52Ce02ivViLZnxIgjFnACecQgTr8EmhwOWS2BcbNOvkBd7Pbs vX1Z3tgfaloiXKKLhRAEjsbSU3Us/vH5fhciwg/dX6RHsWcSaduoHLM3eGc6yZNGmyT/ tQ7PiuNZFVUb+hw2qMj20N1TWTKXRgOk9e1kYIrfNGrXuBO0fo4d4//1W7AcCiZKjvP/ oJnA== X-Gm-Message-State: AOAM532xlK3hJvKyci1rK10npp3bjXDaXH6F05utl3zr9n2ZJGcGP/sg RQyBcAVpGIBc+wg+Us98kju0QNDjRQWutfQk X-Google-Smtp-Source: ABdhPJzoH5zl5rW6rHnNYJGnW2h60I0jgpS+TLruADGDiDeW06g6KJM3JAKPTCN7tel/p4ShyIA+Ww== X-Received: by 2002:a5d:47af:: with SMTP id 15mr8229570wrb.205.1612431302757; Thu, 04 Feb 2021 01:35:02 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id g16sm5280580wmi.30.2021.02.04.01.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 01:35:02 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Feb 2021 09:34:52 +0000 Message-Id: <20210204093457.6879-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210204093457.6879-1-david.plowman@raspberrypi.com> References: <20210204093457.6879-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/7] ipa: raspberrypi: AWB: Improve locking. 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" Fix a couple of places where notify_one() was called with the lock held. Also restartAsync doesn't need the lock for its entire duration. This change exactly matches commit db552b where we do the same for ALSC (the asynchronous thread arrangement there is identical). Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index dabab726..791b5108 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -136,8 +136,8 @@ Awb::~Awb() { std::lock_guard lock(mutex_); async_abort_ = true; - async_signal_.notify_one(); } + async_signal_.notify_one(); async_thread_.join(); } @@ -239,11 +239,14 @@ void Awb::restartAsync(StatisticsPtr &stats, double lux) : (mode_ == nullptr ? config_.default_mode : mode_); lux_ = lux; frame_phase_ = 0; - async_start_ = true; async_started_ = true; size_t len = mode_name_.copy(async_results_.mode, sizeof(async_results_.mode) - 1); async_results_.mode[len] = '\0'; + { + std::lock_guard lock(mutex_); + async_start_ = true; + } async_signal_.notify_one(); } @@ -297,7 +300,6 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) LOG(RPiAwb, Debug) << "No lux metadata found"; LOG(RPiAwb, Debug) << "Awb lux value is " << lux_status.lux; - std::unique_lock lock(mutex_); if (async_started_ == false) restartAsync(stats, lux_status.lux); } @@ -319,8 +321,8 @@ void Awb::asyncFunc() { std::lock_guard lock(mutex_); async_finished_ = true; - sync_signal_.notify_one(); } + sync_signal_.notify_one(); } }