From patchwork Fri Dec 3 16:46:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15015 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 51614BF415 for ; Fri, 3 Dec 2021 16:46:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A38B660839; Fri, 3 Dec 2021 17:46:32 +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="btAo1BcM"; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BD3760822 for ; Fri, 3 Dec 2021 17:46:30 +0100 (CET) Received: by mail-pl1-x635.google.com with SMTP id y8so2520197plg.1 for ; Fri, 03 Dec 2021 08:46:30 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=w4rnq1G43kcabXi0+eiMWXx37SsnfadSaV/7HNh2lW0=; b=btAo1BcMbMj+RinFkMTr88KsEwPLFIf0Vv8Mh7oUoiSG9ayAzkN09MTXpZML4aylB+ ypOmnSuAuW1O/mDnkknj1lT+oJLtTHkkUptVMZdsGBH4KJVTCvE1rzkbg97zMgpDpacr EMJTuJ1Ppk+iy6+w+19O/q/Ay80A3HBcjJJ1U= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=w4rnq1G43kcabXi0+eiMWXx37SsnfadSaV/7HNh2lW0=; b=vafoh5Px3X/+5Bcq4IhICwo+XeFTW1SDVlHyt5MQQsTvLmU8uTgEWDV+7+cDxarX4U eIJ61l+SzNhu5UY+gv09suseo1Q/NOEeQXcwStUMitoMYwnkd09ahRGdIdfLuu/vgAG7 X+ZkgPkFVNWF5id/mdzudtZf7vP2mEnXnFDTwqEsG0eNR45bV0B6uvtCZoYMhfZjL+Fw efjpJefuRRoDboUWbe1Rca4aT8tiZSv9YgpUdG413Htt9ODic7wtnDmCo+9yWxFBCpE2 P/0vsIdFkZhf1wFO7pMu6Sg3TTLI500cDoXn8gha1cmVsdFRT874E+orHea5rC2KsMA5 qmiw== X-Gm-Message-State: AOAM532nqzcTObxmj+Zwu12FLwLnmmOI/go2syktDhJrymevgc6M2zD2 pwwy0QNGHROwveNYKUx0FPZ6+Qyoijuk1A== X-Google-Smtp-Source: ABdhPJysUbbtNx4EPcXgpwaNS2CTGkU7ntO6GRhNWKzjlqS/lU8q/lt6ZfvQALPttB7TdWRhLhLCAw== X-Received: by 2002:a17:902:c3cc:b0:141:be17:405e with SMTP id j12-20020a170902c3cc00b00141be17405emr23932328plj.76.1638549988315; Fri, 03 Dec 2021 08:46:28 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id h18sm4123149pfh.172.2021.12.03.08.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 08:46:27 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 01:46:14 +0900 Message-Id: <20211203164619.1541033-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203164619.1541033-1-hiroh@chromium.org> References: <20211203164619.1541033-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/7] libcamera: base: thread: Protect exitCode by mutex in exit() 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 fixes the bug that Thread::exit() accesses data_->exitCode without acquiring a lock. Signed-off-by: Hirokazu Honda --- src/libcamera/base/thread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 6bda9d14..abd33a83 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -390,9 +390,11 @@ void Thread::finishThread() * * \context This function is \threadsafe. */ -void Thread::exit(int code) +void Thread::exitint code) { + data_->mutex_.lock(); data_->exitCode_ = code; + data_->mutex_.unlock(); data_->exit_.store(true, std::memory_order_release); EventDispatcher *dispatcher = data_->dispatcher_.load(std::memory_order_relaxed);