From patchwork Mon Jan 20 00:24:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2690 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C78F607A2 for ; Mon, 20 Jan 2020 01:24:43 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A854504 for ; Mon, 20 Jan 2020 01:24:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579479883; bh=U27LJqHdUKh2eK/z9aPBMZOJpM+0sfi7/dMwnBwccGg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pPx0U0KNaDKGknCg0vGPNLpfSKhrHmF5iWqgEIrPaxYxS8Mf3lE3GGrp5lma9nPx3 mh0gSz+sStoPVoiavgXp3PSSUy9ym8XlB1u+sbzY8lW5PX4nUqNlKqUICRvP3izqgg 0MJwncuxoOcrsZYYIFMziVqRZyQdDtUZf38cCakk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jan 2020 02:24:21 +0200 Message-Id: <20200120002437.6633-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200120002437.6633-1-laurent.pinchart@ideasonboard.com> References: <20200120002437.6633-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/19] libcamera: thread: Add a method to return the ID of the current thread 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: , X-List-Received-Date: Mon, 20 Jan 2020 00:24:43 -0000 The current thread ID is useful when logging message to debug concurrency issues. Add a method to retrieve it. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/include/thread.h | 2 ++ src/libcamera/thread.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libcamera/include/thread.h b/src/libcamera/include/thread.h index 37edd4f5138b..819a9879ac56 100644 --- a/src/libcamera/include/thread.h +++ b/src/libcamera/include/thread.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -39,6 +40,7 @@ public: Signal finished; static Thread *current(); + static pid_t currentId(); EventDispatcher *eventDispatcher(); void setEventDispatcher(std::unique_ptr dispatcher); diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index 18ebd16a7e2f..fe32cd677596 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include @@ -62,6 +65,7 @@ private: Thread *thread_; bool running_; + pid_t tid_; Mutex mutex_; @@ -108,6 +112,7 @@ ThreadData *ThreadData::current() * started, set it here. */ ThreadData *data = mainThread.data_; + data->tid_ = syscall(SYS_gettid); currentThreadData = data; return data; } @@ -189,6 +194,7 @@ void Thread::startThread() */ thread_local ThreadCleaner cleaner(this, &Thread::finishThread); + data_->tid_ = syscall(SYS_gettid); currentThreadData = data_; run(); @@ -308,6 +314,20 @@ Thread *Thread::current() return data->thread_; } +/** + * \brief Retrieve the ID of the current thread + * + * The thread ID corresponds to the Linux thread ID (TID) as returned by the + * gettid system call. + * + * \return The ID of the current thread + */ +pid_t Thread::currentId() +{ + ThreadData *data = ThreadData::current(); + return data->tid_; +} + /** * \brief Set the event dispatcher * \param[in] dispatcher Pointer to the event dispatcher