From patchwork Sun May 23 02:31:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12364 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 751F9C3200 for ; Sun, 23 May 2021 02:32:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4DB1F68921; Sun, 23 May 2021 04:32:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="e97OAABc"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F5CE68911 for ; Sun, 23 May 2021 04:32:01 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E03F89A; Sun, 23 May 2021 04:32:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1621737121; bh=ekMaN0LjvgaW6Wcf8DnKW8+/k+nO8ZduHf1bqtbnB3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e97OAABcdu5xFVRimB3Hp9Hvd2ocRgbmDVRRe9imq3AABja0JWxD1kJva7I3/5n58 +OZLrrzgXRLNU40N+BMMBaWnEUd8tACw4eZtGbRF5WI532od6JjFDzorTj//faXard IJ7/sArAqKXKzO/iGVoI7X0gG8//eE4+ivEmHANg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 23 May 2021 05:31:52 +0300 Message-Id: <20210523023155.20268-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210523023155.20268-1-laurent.pinchart@ideasonboard.com> References: <20210523023155.20268-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libcamera: thread: Document dispatchMessages() thread-safety requirements 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" The Thread class is incorrectly documented as thread-safe, as the dispatchMessages() function isn't thread-safe. Fix the documentation by tagging individual functions as thread-safe as appropriate. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/libcamera/thread.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index 198670de33a2..285b808332e8 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -229,8 +229,6 @@ ThreadData *ThreadData::current() * called. The event loop dispatches events (messages, notifiers and timers) * sent to the objects living in the thread. This behaviour can be modified by * overriding the run() function. - * - * \context This class is \threadsafe. */ /** @@ -361,6 +359,8 @@ void Thread::finishThread() * * Calling exit() on a thread that reimplements the run() method and doesn't * call exec() will likely have no effect. + * + * \context This function is \threadsafe. */ void Thread::exit(int code) { @@ -383,6 +383,8 @@ void Thread::exit(int code) * utils::duration::max(), the wait never times out. If the thread is not * running the function returns immediately. * + * \context This function is \threadsafe. + * * \return True if the thread has finished, or false if the wait timed out */ bool Thread::wait(utils::duration duration) @@ -412,6 +414,8 @@ bool Thread::wait(utils::duration duration) * started. This method guarantees that it returns true after the start() * method returns, and false after the wait() method returns. * + * \context This function is \threadsafe. + * * \return True if the thread is running, false otherwise */ bool Thread::isRunning() @@ -427,6 +431,7 @@ bool Thread::isRunning() /** * \brief Retrieve the Thread instance for the current thread + * \context This function is \threadsafe. * \return The Thread instance for the current thread */ Thread *Thread::current() @@ -441,6 +446,8 @@ Thread *Thread::current() * The thread ID corresponds to the Linux thread ID (TID) as returned by the * gettid system call. * + * \context This function is \threadsafe. + * * \return The ID of the current thread */ pid_t Thread::currentId() @@ -455,6 +462,8 @@ pid_t Thread::currentId() * This function retrieves the internal event dispatcher for the thread. The * returned event dispatcher is valid until the thread is destroyed. * + * \context This function is \threadsafe. + * * \return Pointer to the event dispatcher */ EventDispatcher *Thread::eventDispatcher() @@ -544,6 +553,10 @@ void Thread::removeMessages(Object *receiver) * This function immediately dispatches all the messages previously posted for * this thread with postMessage() that match the message \a type. If the \a type * is Message::Type::None, all messages are dispatched. + * + * Messages shall only be dispatched from the current thread, typically within + * the thread from the run() function. Calling this function outside of the + * thread results in undefined behaviour. */ void Thread::dispatchMessages(Message::Type type) {