{"id":11745,"url":"https://patchwork.libcamera.org/api/patches/11745/?format=json","web_url":"https://patchwork.libcamera.org/patch/11745/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210328213842.18404-1-laurent.pinchart@ideasonboard.com>","date":"2021-03-28T21:38:42","name":"[libcamera-devel] libcamera: thread: Remove the unused setEventDispatcher() function","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"35835d9d0e85e37b2f31414545d18fedbc7594d4","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11745/mbox/","series":[{"id":1854,"url":"https://patchwork.libcamera.org/api/series/1854/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1854","date":"2021-03-28T21:38:42","name":"[libcamera-devel] libcamera: thread: Remove the unused setEventDispatcher() function","version":1,"mbox":"https://patchwork.libcamera.org/series/1854/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11745/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11745/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 45827C32ED\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Mar 2021 21:39:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 795C568784;\n\tSun, 28 Mar 2021 23:39:30 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E8946084F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Mar 2021 23:39:29 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1E322323\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Mar 2021 23:39:29 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"oPlnL4GS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1616967569;\n\tbh=NA+8ukF/sp1/tK49cxasSEW+dXmLyNhWQEeTwlX6g/M=;\n\th=From:To:Subject:Date:From;\n\tb=oPlnL4GSdX/Bk3lT67XrkfvZ+CZRCmoFWs7g5/Ij6shxmHFHm6EYxgjP26E9czfNo\n\tNzaKgotU/3ZzONSMWJWFDJYjLJUxr+rztGBGg+5e/vfJgNztiP7ZS+/qrn0jfp/Wqm\n\tcBDJ30rfu1hzUawCqqTTFuOcLXWSWUooYXpRT+4E=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 29 Mar 2021 00:38:42 +0300","Message-Id":"<20210328213842.18404-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.28.1","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH] libcamera: thread: Remove the unused\n\tsetEventDispatcher() function","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Custom event dispatchers for threads was an API meant to provide a way\nto integrate libcamera in the application's event loop. This isn't used\nanymore, as libcamera now creates internal threads. Drop the unused\nThread::setEventDispatcher() function, and update the documentation\naccordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/thread.h |  1 -\n src/libcamera/thread.cpp            | 71 ++++++++++++-----------------\n 2 files changed, 29 insertions(+), 43 deletions(-)","diff":"diff --git a/include/libcamera/internal/thread.h b/include/libcamera/internal/thread.h\nindex f6367a8f448b..25d0308d05b4 100644\n--- a/include/libcamera/internal/thread.h\n+++ b/include/libcamera/internal/thread.h\n@@ -46,7 +46,6 @@ public:\n \tstatic pid_t currentId();\n \n \tEventDispatcher *eventDispatcher();\n-\tvoid setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);\n \n \tvoid dispatchMessages(Message::Type type = Message::Type::None);\n \ndiff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp\nindex f339dab165b6..8261307628f8 100644\n--- a/src/libcamera/thread.cpp\n+++ b/src/libcamera/thread.cpp\n@@ -28,6 +28,13 @@\n  * interactions with application threads. Careful compliance with the threading\n  * model will ensure avoidance of race conditions.\n  *\n+ * Every thread created by libcamera is associated with an instance of the\n+ * Thread class. Those threads run by default an internal event loop to\n+ * dispatch events to objects. Additionally, the main thread of the application\n+ * (defined as the thread that calls CameraManager::start()) is also associated\n+ * with a Thread instance, but has no event loop accessible to libcamera. Other\n+ * application threads are not visible to libcamera.\n+ *\n  * \\section thread-objects Threads and Objects\n  *\n  * Instances of the Object class and all its derived classes are thread-aware\n@@ -39,13 +46,12 @@\n  * explicitly connected with ConnectionTypeDirect, will also be delivered from\n  * the object thread's event loop.\n  *\n- * All Object instances created by libcamera are bound to an internal thread,\n- * and applications don't need to provide an event loop to support them. Object\n- * instances created by applications require an event loop. It is the\n- * responsibility of applications to provide that event loop, either explicitly\n- * through CameraManager::setEventDispatcher(), or by running the default event\n- * loop provided by CameraManager::eventDispatcher() in their main thread. The\n- * main thread of an application is the one that calls CameraManager::start().\n+ * All Object instances created internally by libcamera are bound to internal\n+ * threads. As objects interact with thread event loops for proper operation,\n+ * creating an Object instance in a thread that has no internal event loop (such\n+ * as the main application thread, or libcamera threads that have a custom main\n+ * loop), prevents some features of the Object class from being used. See\n+ * Thread::exec() for more details.\n  *\n  * \\section thread-signals Threads and Signals\n  *\n@@ -220,9 +226,9 @@ ThreadData *ThreadData::current()\n  * with the Object, Signal and EventDispatcher classes.\n  *\n  * Thread instances by default run an event loop until the exit() method is\n- * called. A custom event dispatcher may be installed with\n- * setEventDispatcher(), otherwise a poll-based event dispatcher is used. This\n- * behaviour can be overriden by overloading the run() method.\n+ * called. The event loop dispatches events (messages, notifiers and timers)\n+ * sent to the objects living in the thread. This behaviour can be overriden by\n+ * overloading the run() function.\n  *\n  * \\context This class is \\threadsafe.\n  */\n@@ -317,9 +323,17 @@ int Thread::exec()\n  * \\brief Main method of the thread\n  *\n  * When the thread is started with start(), it calls this method in the context\n- * of the new thread. The run() method can be overloaded to perform custom\n- * work. When this method returns the thread execution is stopped, and the \\ref\n- * finished signal is emitted.\n+ * of the new thread. The run() method can be overridden to perform custom\n+ * work, either custom initialization and cleanup before and after calling the\n+ * Thread::exec() function, or a custom thread loop altogether. When this\n+ * method returns the thread execution is stopped, and the \\ref finished signal\n+ * is emitted.\n+ *\n+ * Note that if this function is overriden and doesn't call Thread::exec(), no\n+ * events will be dispatched to the objects living in the thread. These objects\n+ * will not be able to use the EventNotifier, Timer or Message facilities. This\n+ * includes functions that rely on message dispatching, such as\n+ * Object::deleteLater().\n  *\n  * The base implementation just calls exec().\n  */\n@@ -435,38 +449,11 @@ pid_t Thread::currentId()\n \treturn data->tid_;\n }\n \n-/**\n- * \\brief Set the event dispatcher\n- * \\param[in] dispatcher Pointer to the event dispatcher\n- *\n- * Threads that run an event loop require an event dispatcher to integrate\n- * event notification and timers with the loop. Users that want to provide\n- * their own event dispatcher shall call this method once and only once before\n- * the thread is started with start(). If no event dispatcher is provided, a\n- * default poll-based implementation will be used.\n- *\n- * The Thread takes ownership of the event dispatcher and will delete it when\n- * the thread is destroyed.\n- */\n-void Thread::setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher)\n-{\n-\tif (data_->dispatcher_.load(std::memory_order_relaxed)) {\n-\t\tLOG(Thread, Warning) << \"Event dispatcher is already set\";\n-\t\treturn;\n-\t}\n-\n-\tdata_->dispatcher_.store(dispatcher.release(),\n-\t\t\t\t std::memory_order_relaxed);\n-}\n-\n /**\n  * \\brief Retrieve the event dispatcher\n  *\n- * This method retrieves the event dispatcher set with setEventDispatcher().\n- * If no dispatcher has been set, a default poll-based implementation is created\n- * and returned, and no custom event dispatcher may be installed anymore.\n- *\n- * The returned event dispatcher is valid until the thread is destroyed.\n+ * This function retrieves the internal event dispatcher for the thread. The\n+ * returned event dispatcher is valid until the thread is destroyed.\n  *\n  * \\return Pointer to the event dispatcher\n  */\n","prefixes":["libcamera-devel"]}