From patchwork Fri Dec 3 16:46:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15016 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 63F8DBF415 for ; Fri, 3 Dec 2021 16:46:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1938560822; Fri, 3 Dec 2021 17:46:35 +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="FeSYt4Ow"; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ECEF360822 for ; Fri, 3 Dec 2021 17:46:31 +0100 (CET) Received: by mail-pj1-x102a.google.com with SMTP id iq11so2758065pjb.3 for ; Fri, 03 Dec 2021 08:46:31 -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=pI8V8gbQRxT9tr/AaPVKtqTwDKeOmbZ37IXXJs9oD0Q=; b=FeSYt4Ow1X9Hob9sGY/yqRYnwtSxaCDpkQwomurTOgT1kt8gxRiuN+Y8wtTgxnhqDC ro507TeUFglyjFJ4ed5LQsHhd259sYYcqksT7tRZOT106C59+lEyHoavQ7i8NPy1zC2d y437GbUMrcWBveq9JhciS/kI+pCmKJ9v8hB8Q= 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=pI8V8gbQRxT9tr/AaPVKtqTwDKeOmbZ37IXXJs9oD0Q=; b=7Q7LC9L8S8AuQR2kxcqzSpeydeUm8Itn9YKkvWiNbHI4dJ780sBOPCR/5K8c75P6jf kIas/4nBtANl0+kxKL8koKt+1ExKK7VIuspWWXlsDUiaAbXmTbRxOEYsZaL/ikekn+Z9 VrXkr2mT9QkPWEB57uUP6EqxVJkM7kuES15oZYHk4gq3dWEch6h80C4IvOQsMwv6cW9S pQxyY2InrUK7RkaoQAbMnMjMG1GG3EWWL9ljU0K8VpMXLqqAIk8uV6rLuO8lXergqCcE Rxtx6iXK1MBDlGQWoxw/4jR4Z87WjMoSf4dsGr9JtPkEc/jcr8iG/Y2ORgChPjp4xNBJ xXwg== X-Gm-Message-State: AOAM531T3ppjnbb81BzbR14N0f1zIEKq2L0hHQz7UwB7F7i76XUWBiUS 8OgnrCgjNaFGnqFLgLPh6Blb+EslAf2qRw== X-Google-Smtp-Source: ABdhPJx//5GFSsakAGfXOSSc3JZbZsrQlEePLvi8P/Zvl6EOvatiwLWeRB78I8d/Dkdl1sQuwwn0aQ== X-Received: by 2002:a17:902:904b:b0:143:73ff:eb7d with SMTP id w11-20020a170902904b00b0014373ffeb7dmr23451270plz.85.1638549989989; Fri, 03 Dec 2021 08:46:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 08:46:29 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 01:46:15 +0900 Message-Id: <20211203164619.1541033-4-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 3/7] libcamera: base: thread: Apply clang thread safety annotation 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 annotates member variables of ThreadData by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/libcamera/base/thread.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index abd33a83..205f3d1b 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -151,7 +151,7 @@ private: friend class ThreadMain; Thread *thread_; - bool running_; + bool running_ LIBCAMERA_TSA_GUARDED_BY(mutex_); pid_t tid_; Mutex mutex_; @@ -160,7 +160,7 @@ private: ConditionVariable cv_; std::atomic exit_; - int exitCode_; + int exitCode_ LIBCAMERA_TSA_GUARDED_BY(mutex_); MessageQueue messages_; }; @@ -390,7 +390,7 @@ void Thread::finishThread() * * \context This function is \threadsafe. */ -void Thread::exitint code) +void Thread::exit(int code) { data_->mutex_.lock(); data_->exitCode_ = code; @@ -424,11 +424,19 @@ bool Thread::wait(utils::duration duration) { MutexLocker locker(data_->mutex_); - if (duration == utils::duration::max()) - data_->cv_.wait(locker, [&]() { return !data_->running_; }); - else - hasFinished = data_->cv_.wait_for(locker, duration, - [&]() { return !data_->running_; }); + if (duration == utils::duration::max()) { + data_->cv_.wait( + locker, + [&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) { + return !data_->running_; + }); + } else { + hasFinished = data_->cv_.wait_for( + locker, duration, + [&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) { + return !data_->running_; + }); + } } if (thread_.joinable())