[{"id":3529,"web_url":"https://patchwork.libcamera.org/comment/3529/","msgid":"<20200120113247.nofpsq3tygcv7lqz@uno.localdomain>","date":"2020-01-20T11:32:47","subject":"Re: [libcamera-devel] [PATCH 03/19] libcamera: thread: Add a method\n\tto return the ID of the current thread","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Jan 20, 2020 at 02:24:21AM +0200, Laurent Pinchart wrote:\n> The current thread ID is useful when logging message to debug\n> concurrency issues. Add a method to retrieve it.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nThanks\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\n> ---\n>  src/libcamera/include/thread.h |  2 ++\n>  src/libcamera/thread.cpp       | 20 ++++++++++++++++++++\n>  2 files changed, 22 insertions(+)\n>\n> diff --git a/src/libcamera/include/thread.h b/src/libcamera/include/thread.h\n> index 37edd4f5138b..819a9879ac56 100644\n> --- a/src/libcamera/include/thread.h\n> +++ b/src/libcamera/include/thread.h\n> @@ -9,6 +9,7 @@\n>\n>  #include <memory>\n>  #include <mutex>\n> +#include <sys/types.h>\n>  #include <thread>\n>\n>  #include <libcamera/signal.h>\n> @@ -39,6 +40,7 @@ public:\n>  \tSignal<Thread *> finished;\n>\n>  \tstatic Thread *current();\n> +\tstatic pid_t currentId();\n>\n>  \tEventDispatcher *eventDispatcher();\n>  \tvoid setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);\n> diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp\n> index 18ebd16a7e2f..fe32cd677596 100644\n> --- a/src/libcamera/thread.cpp\n> +++ b/src/libcamera/thread.cpp\n> @@ -9,6 +9,9 @@\n>\n>  #include <atomic>\n>  #include <list>\n> +#include <unistd.h>\n> +#include <sys/syscall.h>\n> +#include <sys/types.h>\n>\n>  #include <libcamera/event_dispatcher.h>\n>\n> @@ -62,6 +65,7 @@ private:\n>\n>  \tThread *thread_;\n>  \tbool running_;\n> +\tpid_t tid_;\n>\n>  \tMutex mutex_;\n>\n> @@ -108,6 +112,7 @@ ThreadData *ThreadData::current()\n>  \t * started, set it here.\n>  \t */\n>  \tThreadData *data = mainThread.data_;\n> +\tdata->tid_ = syscall(SYS_gettid);\n>  \tcurrentThreadData = data;\n>  \treturn data;\n>  }\n> @@ -189,6 +194,7 @@ void Thread::startThread()\n>  \t */\n>  \tthread_local ThreadCleaner cleaner(this, &Thread::finishThread);\n>\n> +\tdata_->tid_ = syscall(SYS_gettid);\n>  \tcurrentThreadData = data_;\n>\n>  \trun();\n> @@ -308,6 +314,20 @@ Thread *Thread::current()\n>  \treturn data->thread_;\n>  }\n>\n> +/**\n> + * \\brief Retrieve the ID of the current thread\n> + *\n> + * The thread ID corresponds to the Linux thread ID (TID) as returned by the\n> + * gettid system call.\n> + *\n> + * \\return The ID of the current thread\n> + */\n> +pid_t Thread::currentId()\n> +{\n> +\tThreadData *data = ThreadData::current();\n> +\treturn data->tid_;\n> +}\n> +\n>  /**\n>   * \\brief Set the event dispatcher\n>   * \\param[in] dispatcher Pointer to the event dispatcher\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 29745600F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jan 2020 12:30:16 +0100 (CET)","from uno.localdomain (93-34-114-233.ip49.fastwebnet.it\n\t[93.34.114.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id BB7DB200005;\n\tMon, 20 Jan 2020 11:30:15 +0000 (UTC)"],"Date":"Mon, 20 Jan 2020 12:32:47 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200120113247.nofpsq3tygcv7lqz@uno.localdomain>","References":"<20200120002437.6633-1-laurent.pinchart@ideasonboard.com>\n\t<20200120002437.6633-4-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"hcrr3algatox3xmb\"","Content-Disposition":"inline","In-Reply-To":"<20200120002437.6633-4-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 03/19] libcamera: thread: Add a method\n\tto return the ID of the current thread","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 20 Jan 2020 11:30:16 -0000"}}]