From patchwork Sat Aug 1 08:01:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9126 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 951FCBD878 for ; Sat, 1 Aug 2020 08:02:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6130261F44; Sat, 1 Aug 2020 10:02:00 +0200 (CEST) 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="WVw+3uUV"; dkim-atps=neutral Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CA3C61F34 for ; Sat, 1 Aug 2020 10:01:58 +0200 (CEST) Received: by mail-wm1-x343.google.com with SMTP id k20so11099567wmi.5 for ; Sat, 01 Aug 2020 01:01:58 -0700 (PDT) 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=6/gEh2ZY2aznNHMFS+s1Y6SPKqzLhNzjjy68vEp8MrE=; b=WVw+3uUVKutxQI+D+AsQL2kiIpKNMo5vJCoOMJVn1GlUxqnzjdCGNcRanIXcPBqVzd iYy7b7zP3Mi646Wc/WMALivG64r9M6OY1ryN6ssnafVUZcgz/Z+gfRdMQJjQcWZk9EBJ g7NYcqI4WS9eyJ09bnxf4pG6afLDvzASjJBxMEorHHtuncCQjNcBbuUZJSgkXcaiye7s uZTWi+CsD+dSKyLU/aKmRIMj8Ekyw7aUAvTGNmCQR+GSewkN4bj1uDLXhYz9XMN8SmHf kj6rq+AI7Cx4vO9TbdYkXIVVTgvSE2L/XFgNNhunNvmp90WbQbZycQ29pjYXXPavMAzK atcA== 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=6/gEh2ZY2aznNHMFS+s1Y6SPKqzLhNzjjy68vEp8MrE=; b=IPRwhDU6ixN371aq9w9Y6gzv3+MVxx4fj2Aq7XDk86COTFUrX4E/6UTI3H4JSAjWjW HLdMGaoSQrW7kgC4Iz1M7zxLOTt9bfAAwdZlM2PqwGIEG7/KzXwba8zT7hx3MsAu9zbW HrfpZN4XszoNkrfC//L3V391IWHcrGiCb/+08CNopZ+mrzAd0WTCePDQUTJKgkz7Pyid yvbz/oTqFsszv/ZfDX9Ph8+rH3RWr+sFUYo10vP4fHCdD6/AHFJmaojmAniZQx9w3cYu 6w6AnU+PkmlPXFFYwGS/0x/bEuqgRrX1iK55Z34cJ0RNmq2GuW0Jt6mi5nymRSTe4slr oZPQ== X-Gm-Message-State: AOAM5323pA+GT7/HjBrr1kwONNI+RGNS0eabAWt7unfdkbEOsbA7oynn pGQW1rdUXerHAvxiA9gxWrKTnHuDADCi8w== X-Google-Smtp-Source: ABdhPJyao8QKPSeG6WvLL5I8zIGnj3zDeTLALzfn1XrqRn8R1s9icXl/SBMho2m2EA4BYwDmMTLNcA== X-Received: by 2002:a1c:3285:: with SMTP id y127mr7127980wmy.104.1596268917523; Sat, 01 Aug 2020 01:01:57 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id l67sm17385253wml.13.2020.08.01.01.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 01:01:57 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Sat, 1 Aug 2020 09:01:49 +0100 Message-Id: <20200801080151.4282-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200801080151.4282-1-david.plowman@raspberrypi.com> References: <20200801080151.4282-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] libcamera: ipa: raspberrypi: ALSC: Improve locking in a few places 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 up a few locations where we call notify_one() with the lock held. In particular, restartAsync does not need to be called with the lock held for its entire duration. Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart Reviewed-by: Naushir Patuck Reported-by: Coverity CID=298183 --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 76e2f04..12359dc 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -32,8 +32,8 @@ Alsc::~Alsc() { std::lock_guard lock(mutex_); async_abort_ = true; - async_signal_.notify_one(); } + async_signal_.notify_one(); async_thread_.join(); } @@ -268,8 +268,11 @@ void Alsc::restartAsync(StatisticsPtr &stats, Metadata *image_metadata) frame_phase_ = 0; // copy the camera mode so it won't change during the calculations async_camera_mode_ = camera_mode_; - async_start_ = true; async_started_ = true; + { + std::lock_guard lock(mutex_); + async_start_ = true; + } async_signal_.notify_one(); } @@ -315,7 +318,6 @@ void Alsc::Process(StatisticsPtr &stats, Metadata *image_metadata) RPI_LOG("Alsc: frame_phase " << frame_phase_); if (frame_phase_ >= (int)config_.frame_period || frame_count2_ < (int)config_.startup_frames) { - std::unique_lock lock(mutex_); if (async_started_ == false) { RPI_LOG("ALSC thread starting"); restartAsync(stats, image_metadata); @@ -339,8 +341,8 @@ void Alsc::asyncFunc() { std::lock_guard lock(mutex_); async_finished_ = true; - sync_signal_.notify_one(); } + sync_signal_.notify_one(); } }